Created
December 14, 2023 08:14
-
-
Save sekstini/3178bac33d63e6dc9b3d102095f30a75 to your computer and use it in GitHub Desktop.
aoc 14 part 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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