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