Created
December 28, 2020 16:23
-
-
Save joshbduncan/bfb162a038850f72b505a9baa42b3d01 to your computer and use it in GitHub Desktop.
This file contains 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(match): | |
pdict = {} | |
for i, p in enumerate(data): | |
pdict[int(p)] = i + 1 | |
turn = len(pdict) + 1 | |
same = 0 | |
while turn < match: | |
if same in pdict: | |
diff = turn - pdict[same] | |
pdict[same] = turn | |
else: | |
diff = 0 | |
pdict[same] = turn | |
same = diff | |
turn += 1 | |
return same | |
data = open("day15.in").read().strip().split(',') | |
print(f'Part 1: {solve(2020)}') | |
print(f'Part 2: {solve(30000000)}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment