From 5317bade8af4438a914aa24423e4cf76bc704980 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Wed, 16 Dec 2020 14:10:26 +0100 Subject: [PATCH] Add day 15 --- d15.py | 22 ++++++++++++++++++++++ d15_input.txt | 1 + d15_output.txt | 2 ++ 3 files changed, 25 insertions(+) create mode 100755 d15.py create mode 100644 d15_input.txt create mode 100644 d15_output.txt diff --git a/d15.py b/d15.py new file mode 100755 index 0000000..03d8b9f --- /dev/null +++ b/d15.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +from sys import argv + +i = [int(x) for x in open(argv[1]).read().strip().split(",")] + +a = {x:t+1 for t,x in enumerate(i[:-1])} +t = len(i) +l = i[-1] +def f(x): + global l,t + while t < x: + if l in a: + n = t - a[l] + else: + n = 0 + a[l] = t + t += 1 + l = n + return l +print(f(2020)) +print(f(30000000)) diff --git a/d15_input.txt b/d15_input.txt new file mode 100644 index 0000000..69009f0 --- /dev/null +++ b/d15_input.txt @@ -0,0 +1 @@ +0,13,16,17,1,10,6 diff --git a/d15_output.txt b/d15_output.txt new file mode 100644 index 0000000..155aa75 --- /dev/null +++ b/d15_output.txt @@ -0,0 +1,2 @@ +276 +31916