Type up to 2,000 in the box
Same seed + size = same map
Playback
Space = play/pause
Planning 0 s

Calories banked over time

    Each step up is a meal. A step down is spoiled food. Hover, or focus the chart and use ← →, to read exact values.

    Results on this map

    Show both routes, meal by meal

    How it works

    Scoring

    Each food type has a calorie value and a shelf life. Freshness drops in a straight line from 1 (fresh) to 0 (spoiled) over that shelf life, and eating an item at time t is worth

    score(t) = calories × (1 − t / shelf life) = calories − w·t,   where w = calories / shelf life

    So the total score is (all calories on the map) − Σ wi·ti. The first part is the same for every route, so maximizing calories is the same as minimizing the weighted sum of arrival times, which makes this a weighted Traveling Repairman problem. The raccoon walks 1 m/s in straight lines and eats instantly.

    Greedy · straightforward

    Standing where it is, the raccoon scores every uneaten item and walks to the most attractive one, then repeats. Attractiveness is Smith's ratio rule: calories lost per second of waiting ÷ seconds of walking to it. It never looks more than one step ahead.

    GREEDY-RACCOON(items, den, speed)
     1  here ← den;  clock ← 0
     2  remaining ← all n items;  route ← empty
     3  while remaining is not empty
     4      best ← NIL;  best_value ← −∞
     5      for each item j in remaining
     6          travel ← distance(here, j) / speed
     7          value  ← w_j / travel
     8          if value > best_value
     9              best ← j;  best_value ← value
    10      walk to best;  clock ← clock + travel
    11      remove best from remaining;  append to route
    12  return route
    Time
    Θ(n²): lines 6–9 run n + (n−1) + … + 1 times
    Memory
    Θ(n)

    Greedy + 2-opt · clever

    Step 1: build exactly Greedy's route, but faster. All items of one food type share the same w, so the best fish is just the nearest fish. One k-d tree per food type answers "nearest uneaten fish?" in O(log n). Step 2: repeatedly pick a stretch of the route and walk it backwards when that loses fewer calories. Running totals of the stretch's walking time, weight and internal cost make each check O(1).

    TWO-OPT-RACCOON(items, den, L, P)
     1  route ← GREEDY-KD(items, den)
     2  repeat at most P times
     3      improved ← false
     4      for i ← 1 to n
     5          for j ← i+1 to min(n, i+L−1)
     6              Δ ← change in spoilage if route[i..j]
                        is reversed                  ▹ O(1)
     7              if Δ < 0
     8                  reverse route[i..j]           ▹ Θ(n)
     9                  improved ← true
    10      if not improved: stop
    11  return route
    Time
    O(n log² n + P·n·L + M·n) expected, with L = 50 and P = 20 fixed and M = flips accepted. On random maps M grows like 0.3·n, so in practice this is about n², the same order as Greedy. 2-opt's advantage is the score, not asymptotic speed.
    Memory
    Θ(n)

    About this page

    The algorithms are a TypeScript port of the group's Python implementation (ai-claude/raccoon/). Automated tests check that both versions produce identical routes. Timings are measured in your browser (wall-clock, averaged over repeated runs), so they differ from the Python benchmark numbers. Maps here use a different random number generator than Python, so a seed on this page is not the same map as that seed in python main.py demo.

    References (verify before citing): W. E. Smith, Naval Research Logistics Quarterly 3, 1956 (ratio rule) · J. L. Bentley, CACM 18(9), 1975 (k-d trees) · G. A. Croes, Operations Research 6(6), 1958 (2-opt) · Silva et al., EJOR 221(3), 2012 (O(1) move evaluation for minimum latency).