Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,87 @@
[String] data
V nrows = 0
V px = 0
V py = 0
V sdata =
V ddata =
F init(board)
:data = board.split("\n")
:nrows = max(:data.map(r -> r.len))
V maps = [ = , . = ., @ = , # = #, $ = ]
V mapd = [ = , . = , @ = @, # = , $ = *]
L(row) :data
V r = L.index
L(ch) row
V c = L.index
:sdata = maps[ch]
:ddata = mapd[ch]
I ch == @
:px = c
:py = r
F push(x, y, dx, dy, &data)
I :sdata[(y + 2 * dy) * :nrows + x + 2 * dx] == #
| data[(y + 2 * dy) * :nrows + x + 2 * dx] !=
data =
R
data[y * :nrows + x] =
data[(y + dy) * :nrows + x + dx] = @
data[(y + 2 * dy) * :nrows + x + 2 * dx] = *
F is_solved(data)
L(i) 0 .< data.len
I (:sdata[i] == .) != (data[i] == *)
R 0B
R 1B
F solve()
V open = Deque([(:ddata, , :px, :py)])
V visited = Set([:ddata])
V dirs = ((0, -1, u, U), ( 1, 0, r, R),
(0, 1, d, D), (-1, 0, l, L))
L !open.empty
V (cur, csol, x, y) = open.pop_left()
L(di) dirs
V temp = copy(cur)
V (dx, dy) = (di[0], di[1])
I temp[(y + dy) * :nrows + x + dx] == *
push(x, y, dx, dy, &temp)
I temp != & temp !C visited
I is_solved(temp)
R csoldi[3]
open.append((temp, csoldi[3], x + dx, y + dy))
visited.add(temp)
E
I :sdata[(y + dy) * :nrows + x + dx] == # | temp[(y + dy) * :nrows + x + dx] !=
L.continue
temp[y * :nrows + x] =
temp[(y + dy) * :nrows + x + dx] = @
I temp !C visited
I is_solved(temp)
R csoldi[2]
open.append((temp, csoldi[2], x + dx, y + dy))
visited.add(temp)
R No solution
V level =
|#######
# #
# #
#. # #
#. $$ #
#.$$ #
#.# @#
#######
init(level)
print(level"\n\n"solve())