From 97d2ca55e7b3554c495e488f0c3f2cb8c44b4a9c Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Mon, 14 Dec 2020 10:21:49 -0600 Subject: [PATCH] Day13 --- 2020/src/day13.nim | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/2020/src/day13.nim b/2020/src/day13.nim index 9c2e255..6716510 100644 --- a/2020/src/day13.nim +++ b/2020/src/day13.nim @@ -1,3 +1,35 @@ -import streams -proc part1*(s: Stream): int = 9 -proc part2*(s: Stream): int = 9 +import streams, sequtils, strutils + +proc part1*(s: Stream): int = + let schedule = toSeq(s.lines) + let departure = schedule[0].parseInt + var ss = schedule[1].split(",").filterIt(it != "x" and it != "").map(parseInt) + var mn = (0, departure*2) + for n in ss: + let q = n * ((departure div n) + 1) + if q < mn[1]: + mn = (n, q) + mn[0] * (mn[1] - departure) + +import tables +proc part2*(s: Stream): int = + var ss = toSeq(s.lines)[1].split(",").filterIt(it != "") + var bb = initTable[int, int]() + for n in 0..