Formatting

Signed-off-by: AKU <tom@tdpain.net>
This commit is contained in:
akp 2021-12-11 13:08:25 +00:00
parent 9ce1e05bfa
commit 41f60123e7
No known key found for this signature in database
GPG key ID: AA5726202C8879B7

View file

@ -10,7 +10,7 @@ proc parse(instr: string): Cave =
for x, digitChar in line.pairs:
result[(x, y)] = parseInt($digitChar)
proc getAdjacentPoints(point: Point): seq[Point] =
proc getAdjacentPoints(point: Point): seq[Point] =
let (x, y) = point
return @[
(x, y - 1),
@ -31,7 +31,7 @@ proc iterate(cave: Cave): (Cave, int, bool) =
var updates = Cave()
var hasFlashed: seq[Point]
proc handleNine(point: Point) =
updates[point] = 0
hasFlashed.add(point)
@ -42,7 +42,7 @@ proc iterate(cave: Cave): (Cave, int, bool) =
var previousValue = cave[adjacent]
if adjacent in updates:
previousValue = updates[adjacent]
updates[adjacent] = previousValue + 1
if previousValue + 1 > 9 and not (adjacent in hasFlashed):
@ -55,7 +55,7 @@ proc iterate(cave: Cave): (Cave, int, bool) =
for point in updates.keys:
cave[point] = updates[point]
for point in hasFlashed:
for point in hasFlashed:
cave[point] = 0
return (cave, hasFlashed.len, hasFlashed.len == cave.len)
@ -70,10 +70,10 @@ proc partOne*(instr: string): int =
result += n
proc partTwo*(instr: string): int =
var cave = parse(instR)
var cave = parse(instr)
while true:
result += 1
let (c, _, allFlashed) = iterate(cave)
if allFlashed:
return
cave = c
cave = c