pico-8 cartridge // http://www.pico-8.com version 41 __lua__ local races = { { 7, 9 }, { 15, 40 }, { 30, 200 } } printh("") printh("aoc 2023 6") printh("") function get_dist(race, t) return (race[1] - t) * t end function trace() line(1, 126, 127, 126, 13) line(1, 126, 1, 1, 13) print("distance", 3, 1, 8) local x, y for race in all(races) do local md = 0 ym = 0 xm = 0 bt = 0 pd = 0 line(2, 126 - race[2] / 2, 127, 126 - race[2] / 2, 2) print("time", 80, 114, 15) print("pressed", 80, 121, 15) line() for i = 0, race[1] do local dist = get_dist(race, i) x = 1 + i * 4 y = 126 - dist / 2 if dist > md then md = dist xm = x ym = y end line(x, y, 7) yield() if pd > dist and bt == 0 then bt = i - 1 end pd = dist end print(md .. "MM", xm - 2, ym - 6, 8) print(bt .. "MS", xm + 20, ym - 6, 15) -- print(race[2],50,126-race[2]/2-6,2) end end local co = cocreate(trace) cls() function _update() coresume(co) end __gfx__ 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000