From 3b55df5ff50a1d52618245ee8fd46a17dbb1af0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Rasmussen?= Date: Mon, 14 Dec 2020 15:49:35 +0100 Subject: [PATCH] Day 13, part 1 --- 2020/13/main.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 2020/13/main.py diff --git a/2020/13/main.py b/2020/13/main.py new file mode 100644 index 0000000..f9cf7d3 --- /dev/null +++ b/2020/13/main.py @@ -0,0 +1,23 @@ +test = ( + 939, + "7,13,x,x,59,x,31,19", +) + +data = ( + 1002462, + "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,601,x,x,x,x,x,x,x,x,x,x,x,19,x,x,x,x,17,x,x,x,x,x,23,x,x,x,x,x,29,x,443,x,x,x,x,x,x,x,x,x,x,x,x,13", +) + + +def part_1(departure, bus_ids): + buses = [int(x) for x in bus_ids.split(",") if x != "x"] + distances = [(departure // x + 1) * x - departure for x in buses] + idx = distances.index(min(distances)) + return buses[idx], distances[idx] + + +id, wait = part_1(*test) +assert id*wait == 295 + +id, wait = part_1(*data) +print(f"1: Answer is {id*wait}")