Paste: aoc 22-12 wrong

Author: razetime
Mode: lua
Date: Mon, 12 Dec 2022 06:00:10
Plain Text |
l:eval[read["../../lib.lil"]].vars
i:"\n" split -1 drop read["../inp/12"]
i:each x in i "%a" parse x end

start:0
en:0
each x in range i
  each y in range i[0]
    if i[x][y]=83 start:x,y i[x][y]:97 end
    if i[x][y]=69 en:x,y    i[x][y]:122 end
  end
end

q:(list start,0)
prev:() dict ()

vis:each x in i
  each y in x 0 end
end

show[start]
show[en]
while q
# each x in range 2
  curr:2 take first q
  if curr~en
    show[first q]
    exit[]
  end
  score:last first q
  vis[curr[0]][curr[1]]:1
  q:1 drop q
  each x in (list curr+0,1),(list curr+1,0),(list curr+0,-1),(list curr+-1,0)
    d:i[x[0]][x[1]]-i[curr[0]][curr[1]]
    if (!!i[x[0]][x[1]])&(d<2)&(d>-1)&!vis[x[0]][x[1]]
      q[count q]:x,score+1
      # prev[x]:curr
    end
  end
  # show[sum l.absv[curr-en]]
  # show[vis]
  # q:l.uniq[q]
end

New Annotation

Summary:
Author:
Mode:
Body: