From b73bcd6aeaa2d4b72b9f6984f44a64c9c9d1e33a Mon Sep 17 00:00:00 2001 From: Nathan van Ofwegen Date: Wed, 16 Dec 2020 19:06:31 +0100 Subject: [PATCH] part 1 day 15 --- day15/day15.py | 43 +++++++++++++++++++++++++++++++++++++++++++ day15/input.txt | 1 + 2 files changed, 44 insertions(+) create mode 100644 day15/day15.py create mode 100644 day15/input.txt diff --git a/day15/day15.py b/day15/day15.py new file mode 100644 index 0000000..adcc071 --- /dev/null +++ b/day15/day15.py @@ -0,0 +1,43 @@ +def part1(): + file = open("input.txt") + lines = [i.strip() for i in file.readlines()] + + numbers = lines[0].split(',') + + history = {} + + final_round = 2020 + last_spoken = '' + + for i in range(0, final_round): + + if i < len(numbers): + print(f'Turn {i + 1}: {numbers[i]}') + last_spoken = numbers[i] + history[last_spoken] = [i] + continue + + if len(history[last_spoken]) == 1: + last_spoken = '0' + history[last_spoken].append(i) + else: + count = len(history[last_spoken]) + last_spoken = str(history[last_spoken][count - 1] - history[last_spoken][count - 2]) + if last_spoken not in history: + history[last_spoken] = [i] + else: + history[last_spoken].append(i) + + # print(f'Turn {i + 1}: {last_spoken}') + + print(f"Part 1: {last_spoken}") + + +def part2(): + pass + # print("Part 2: ") + + +if __name__ == "__main__": + part1() + part2() diff --git a/day15/input.txt b/day15/input.txt new file mode 100644 index 0000000..8285f9b --- /dev/null +++ b/day15/input.txt @@ -0,0 +1 @@ +15,12,0,14,3,1