From 17f4e356315de4c23862fd14fb52ed9d2cdbe438 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Mon, 14 Dec 2020 00:07:20 +0100 Subject: [PATCH] Add day 13 --- d13.py | 20 ++++++++++++++++++++ d13_input.txt | 2 ++ d13_output.txt | 2 ++ 3 files changed, 24 insertions(+) create mode 100755 d13.py create mode 100644 d13_input.txt create mode 100644 d13_output.txt diff --git a/d13.py b/d13.py new file mode 100755 index 0000000..f158bab --- /dev/null +++ b/d13.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +from sys import argv + +i = open(argv[1]).read().split("\n") +a = int(i[0].strip()) +b = [int(x) if x != "x" else None for x in i[1].strip().split(",")] + +e = sorted([(x, x-(a%x)) for x in b if x], key=lambda x: x[1])[0] +print(e[0]*e[1]) + +ma = [(i, x) for i, x in enumerate(b) if x] +ma.sort(key=lambda x: x[1], reverse=True) +s = ma[0][1]-ma[0][0] +m = ma[0][1] +for i, x in ma[1:]: + while x-(s%x) != (i%x if i%x != 0 else x): + s += m + m *= x +print(s) diff --git a/d13_input.txt b/d13_input.txt new file mode 100644 index 0000000..85d03d4 --- /dev/null +++ b/d13_input.txt @@ -0,0 +1,2 @@ +1001796 +37,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,457,x,x,x,x,x,x,x,x,x,x,x,x,13,17,x,x,x,x,x,x,x,x,23,x,x,x,x,x,29,x,431,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,19 diff --git a/d13_output.txt b/d13_output.txt new file mode 100644 index 0000000..76a4b45 --- /dev/null +++ b/d13_output.txt @@ -0,0 +1,2 @@ +261 +807435693182510