advent-of-code/2021/nim/day25.nim

45 lines
1.1 KiB
Nim
Raw Normal View History

2021-12-25 15:01:24 -06:00
import ./common, std/[strutils, hashes, sugar, strformat]
2021-12-25 00:19:28 -06:00
proc p1(input: Lines): uint64 =
2021-12-25 15:01:24 -06:00
var h = input.len
var w = input[0].len
2021-12-25 11:18:14 -06:00
var cukes = input
2021-12-25 15:01:24 -06:00
while true:
echo result
2021-12-25 11:18:14 -06:00
var nextCukes = cukes
2021-12-26 14:56:14 -06:00
echo nextCukes.join("\n")
echo ""
let startHash = cukes.hash
for y,line in cukes.pairs:
2021-12-25 15:01:24 -06:00
for x,c in line.pairs:
let tx = if x >= w - 1: 0 else: x + 1
2021-12-26 14:56:14 -06:00
if c == '>' and cukes[y][tx] == '.':
2021-12-25 15:01:24 -06:00
echo &"{x}, {y} going right"
nextCukes[y][x] = '.'
2021-12-26 14:56:14 -06:00
nextCukes[y][tx] = '>'
cukes = nextCukes
2021-12-25 15:01:24 -06:00
for y,line in cukes.pairs:
for x,c in line.pairs:
let ty = if y >= h - 1: 0 else: y + 1
2021-12-26 14:56:14 -06:00
if c == 'v' and cukes[ty][x] == '.':
2021-12-25 15:01:24 -06:00
echo &"{x}, {y} going down"
2021-12-26 14:56:14 -06:00
nextCukes[y][x] = '.'
2021-12-25 15:01:24 -06:00
nextCukes[ty][x] = 'v'
2021-12-26 14:56:14 -06:00
inc result
2021-12-25 15:01:24 -06:00
if nextCukes.hash == startHash: break
2021-12-25 11:18:14 -06:00
cukes = nextCukes
2021-12-25 00:19:28 -06:00
proc p2(input: Lines): uint64 =
2021-12-25 00:19:50 -06:00
0
2021-12-25 00:19:28 -06:00
2021-12-25 15:01:24 -06:00
doDayX 25, (n: int) => n.loadInput, p1, p2, ("""v...>>.vv>
.vv>>.vv..
>>.>v>...v
>>v>>.>.v.
v>v.vv.v..
>.>>..v...
.vv..>.>v.
v.v..>>v.v
....v..v.>""".split('\n'), 58'u64, 0'u64)