Skip to content

Instantly share code, notes, and snippets.

@youz
Created January 15, 2010 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youz/277967 to your computer and use it in GitHub Desktop.
Save youz/277967 to your computer and use it in GitHub Desktop.
maze solver
;;; from http://okajima.air-nifty.com/b/2010/01/post-abc6.html
(= m (filechars "~/gists/maze_arc/maze.txt") ; or (drain:readc)
w (+ 1 (pos #\newline m))
a (n-of len.m nil)
(a:pos #\S m) '(0)
d 0
route)
(until route
(on p a
(if (is car.p d)
(on n (map [+ _ index] `(1 -1 ,w ,-.w))
(case m.n
#\G (= route cdr.p)
#\ (or= a.n `(,(+ d 1) ,n ,@cdr.p))))))
(++ d))
(map [= m._ #\$] route)
pr.m
**************************
*S* * *
* * * * ************* *
* * * ************ *
* * *
************** ***********
* *
** ***********************
* * G *
* * *********** * *
* * ******* * *
* * *
**************************
(= m(drain:readb)w(+(pos 10 m)1)a(n-of len.m())(a:pos 83 m)'(1)d 0)(map[= m._ 36]
(ccc[while(++ d)(on p a(if(is car.p d)(on n(map[+ _ index]`(1 -1,w,-.w))
(case m.n 71(_:cdr p)32(or= a.n `(,(+ d 1),n,@cdr.p))))))]))(map writeb m)
**************************
*S* *$$$$$ *
*$* *$ * $************* *
*$*$$$* $$************ *
*$$$ * $$$$$ *
**************$***********
* $$$$$$$$$$$$$ *
**$***********************
* $$$$$*$$$$$$$$$$$$$$G *
* * $$$ *********** * *
* * ******* * *
* * *
**************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment