From d8fc12abecee62c0e89e734c0aef13da82b58254 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 9 Dec 2021 09:21:16 -0600 Subject: [PATCH] Probably day 9 part 1 done --- 2021/nine.nim | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 2021/nine.nim diff --git a/2021/nine.nim b/2021/nine.nim new file mode 100644 index 0000000..527ff41 --- /dev/null +++ b/2021/nine.nim @@ -0,0 +1,24 @@ +import ./common, std/[strutils, sequtils, strformat, sugar, sets, math] + +proc toGrid(s: seq[string]): seq[seq[int]] = + for l in s: result.add(l.mapIt(int(it)-int('0'))) + +proc p1(c: seq[seq[int]]): int = + let h = c.len() + let w = c[0].len() + for y,l in c.pairs(): + for x,n in l.pairs(): + if x > 0 and c[y][x-1] <= n: continue + if y > 0 and c[y-1][x] <= n: continue + if x < w-1 and c[y][x+1] <= n: continue + if y < h-1 and c[y+1][x] <= n: continue + result += n + 1 + +doDay(9, (n) => n.loadInput().toGrid(), + p1, + p1, + """2199943210 +3987894921 +9856789892 +8767896789 +9899965678""".split('\n').toGrid(), 15, 15)