Created
December 16, 2020 02:12
-
-
Save MischaDy/675e9bed3e25b0dc9983191b50bcf073 to your computer and use it in GitHub Desktop.
Short(ened) version of my day 15 solution
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
input_ = '6,19,0,5,7,13,1' | |
num_iterations = 30000000 | |
starting_nums = list(map(int, input_.split(','))) | |
last_times_spoken_dict = dict(zip(starting_nums, range(1, len(starting_nums) + 1))) | |
last_time_spoken = None # assume that starting nums contain no duplicates | |
for turn in range(len(starting_nums) + 1, num_iterations + 1): | |
spoken_num = 0 if last_time_spoken is None else (turn - 1) - last_time_spoken | |
last_time_spoken = last_times_spoken_dict[spoken_num] if spoken_num in last_times_spoken_dict else None | |
last_times_spoken_dict[spoken_num] = turn | |
print(spoken_num) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment