Probably day 9 part 1 done
This commit is contained in:
parent
607cb130a3
commit
d8fc12abec
24
2021/nine.nim
Normal file
24
2021/nine.nim
Normal file
|
@ -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)
|
Loading…
Reference in a new issue