You are reading a single comment by @frankenbike and its replies.
Click here to read the full conversation.
-
Nearly caught up (still day 19 to do), but here was my part2 for today (~55ms)
from functools import cache def part2(inp): p1, p2 = inp p1 -= 1 p2 -= 1 moves = list(Counter(map(sum, product(*repeat(range(1, 4), 3)))).items()) @cache def winners(A, B, s1, s2): if s1 >= 21: return (1, 0) if s2 >= 21: return (0, 1) winA = 0 winB = 0 for move, freq in moves: newA = (A + move) % 10 news1 = s1 + newA + 1 x, y = winners(B, newA, s2, news1) winA += y * freq winB += x * freq return (winA, winB) return max(winners(p1, p2, 0, 0))
My solutions:
Quite disappointed that my first instinct was so far off optimal.