Day 25 is done

This commit is contained in:
Daniel Flanagan 2021-12-26 14:56:14 -06:00
parent 43903485ca
commit c1cba6750f
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4

View file

@ -7,32 +7,28 @@ proc p1(input: Lines): uint64 =
while true: while true:
echo result echo result
var nextCukes = cukes var nextCukes = cukes
if result < 4:
echo nextCukes.join("\n") echo nextCukes.join("\n")
echo "" echo ""
let startHash = nextCukes.hash let startHash = cukes.hash
for y,line in nextCukes.pairs: for y,line in cukes.pairs:
for x,c in line.pairs: for x,c in line.pairs:
let tx = if x >= w - 1: 0 else: x + 1 let tx = if x >= w - 1: 0 else: x + 1
if c == '>' and nextCukes[y][tx] == '.': if c == '>' and cukes[y][tx] == '.':
echo &"{x}, {y} going right" echo &"{x}, {y} going right"
nextCukes[y][x] = '.' nextCukes[y][x] = '.'
nextCukes[y][tx] = 'r' nextCukes[y][tx] = '>'
cukes = nextCukes
for y,line in cukes.pairs: for y,line in cukes.pairs:
for x,c in line.pairs: for x,c in line.pairs:
let ty = if y >= h - 1: 0 else: y + 1 let ty = if y >= h - 1: 0 else: y + 1
if c == 'v' and nextCukes[ty][x] == '.': if c == 'v' and cukes[ty][x] == '.':
echo &"{x}, {y} going down" echo &"{x}, {y} going down"
nextCukes[y][x] = 'u' nextCukes[y][x] = '.'
nextCukes[ty][x] = 'v' nextCukes[ty][x] = 'v'
for y,line in nextCukes.pairs:
for x,c in line:
if c == 'u': nextCukes[y][x] = '.'
elif c == 'r': nextCukes[y][x] = '>'
inc result
if nextCukes.hash == startHash: break if nextCukes.hash == startHash: break
cukes = nextCukes cukes = nextCukes
inc result
proc p2(input: Lines): uint64 = proc p2(input: Lines): uint64 =
0 0