day 14 ivy solution

main
magical 2024-12-15 04:20:55 +00:00
parent 0247ce727a
commit b6512dc6c1
2 changed files with 39 additions and 0 deletions

1
day14/input.ivy 100644

File diff suppressed because one or more lines are too long

38
day14/sol.ivy 100644
View File

@ -0,0 +1,38 @@
) 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