adventofcode2024/day14/sol.ivy

39 lines
759 B
Plaintext
Raw Normal View History

2024-12-15 04:20:55 +00:00
) get "input.ivy"
dims = 101 103 # width, height
op t steps A = (A[;1 2] + t * A[;3 4]) mod dims
op show coords =
pic = (*/dims) rho '.'
pic[dims decode transp coords] = '#'
transp dims rho pic
op qscore coords =
x = coords[;1]
y = coords[;2]
m = floor dims / 2
q1 = +/ (x < m[1]) and (y < m[2])
q2 = +/ (x > m[1]) and (y < m[2])
q3 = +/ (x < m[1]) and (y > m[2])
q4 = +/ (x > m[1]) and (y > m[2])
*/(q1, q2, q3, q4)
# qscore@ (iota */dims) @steps A
op v minq t =
t < 0: v[1]
q = qscore (t steps v[3])
q < v[2]: (t, q, box v[3]) minq (t-1)
v minq (t-1)
op find A = (-1 1e100, box A) minq (*/dims)
#show 8270 steps input
qscore 100 steps input
t = find input
show (t steps input)
"t = ", t