Skip to content

Instantly share code, notes, and snippets.

@sekstini
Created December 14, 2023 08:14
Show Gist options
  • Save sekstini/3178bac33d63e6dc9b3d102095f30a75 to your computer and use it in GitHub Desktop.
Save sekstini/3178bac33d63e6dc9b3d102095f30a75 to your computer and use it in GitHub Desktop.
aoc 14 part 2
def solve(g, n=10**9):
seq = [g]
for i in range(n):
if (g := cycle(g)) in seq:
break
seq.append(g)
cycle_len = (i + 1) - (cycle_start := seq.index(g))
final_index = cycle_start + (n - cycle_start) % cycle_len
return calculate_load(seq[final_index])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment