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..