From 12e2fd4d7497972a63ba0bc341db3fa59b6d45b5 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Tue, 15 Dec 2020 16:48:56 +1030 Subject: [PATCH] 2020 day 15 --- 2020/day15.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 2020/day15.py diff --git a/2020/day15.py b/2020/day15.py new file mode 100644 index 0000000..9aa98d0 --- /dev/null +++ b/2020/day15.py @@ -0,0 +1,17 @@ +def play_game(data, until): + last_indices = {v:i for i,v in enumerate(data[:-1])} + last = data[-1] + for i in range(len(data), until): + if last in last_indices: + n = i-last_indices[last]-1 + last_indices[last] = i-1 + last = n + else: + last_indices[last] = i-1 + last = 0 + return last + +input = [int(i) for i in '10,16,6,0,1,17'.split(',')] + +print(f'Part 1: 2020th number is {play_game(input, 2020)}') +print(f'Part 2: 30000000th number is {play_game(input, 30000000)}')