From bf96e41ccbd288f17fe33648487a10da8f240d38 Mon Sep 17 00:00:00 2001 From: Sebastian Seedorf Date: Tue, 15 Dec 2020 09:47:24 +0100 Subject: [PATCH] Day 15 --- day15/input.txt | 1 + day15/part1.py | 25 +++++++++++++++++++++++++ day15/part2.py | 25 +++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 day15/input.txt create mode 100644 day15/part1.py create mode 100644 day15/part2.py diff --git a/day15/input.txt b/day15/input.txt new file mode 100644 index 0000000..69009f0 --- /dev/null +++ b/day15/input.txt @@ -0,0 +1 @@ +0,13,16,17,1,10,6 diff --git a/day15/part1.py b/day15/part1.py new file mode 100644 index 0000000..9d8e34e --- /dev/null +++ b/day15/part1.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +from collections import defaultdict + +lines = (x.strip() for x in open("input.txt")) +nums = defaultdict(list) +TARGET = 2020 + +for line in lines: + print(line) + turn = 0 + last_spoken = 0 + for starting in map(int, line.split(",")): + nums[starting] = [turn] + turn += 1 + last_spoken = starting + for t in range(turn, TARGET): + last = nums[last_spoken] + if len(last) == 2: + n = last[1] - last[0] + else: + n = 0 + nums[n] = nums[n][-1:] + [t] + last_spoken = n + print("->", last_spoken) diff --git a/day15/part2.py b/day15/part2.py new file mode 100644 index 0000000..63a1973 --- /dev/null +++ b/day15/part2.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +from collections import defaultdict + +lines = (x.strip() for x in open("input.txt")) +nums = defaultdict(list) +TARGET = 30000000 + +for line in lines: + print(line) + turn = 0 + last_spoken = 0 + for starting in map(int, line.split(",")): + nums[starting] = [turn] + turn += 1 + last_spoken = starting + for t in range(turn, TARGET): + last = nums[last_spoken] + if len(last) == 2: + n = last[1] - last[0] + else: + n = 0 + nums[n] = nums[n][-1:] + [t] + last_spoken = n + print("->", last_spoken)