Created
February 26, 2013 01:25
-
-
Save NaokiKuzumi/5034983 to your computer and use it in GitHub Desktop.
https://gist.github.com/wasao/5006686 これ見てclで書こうと思ったら波に乗れなかった感。
cf http://d.hatena.ne.jp/ayato0211/20130221/1361438221 http://d.hatena.ne.jp/torazuka/20130221/ddd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defstruct node | |
(rireki nil :type list) | |
(state '(3 2 1 2) :type (and list (not null)))) | |
(defun inner-solve (slist) | |
(if | |
(issolved (car slist)) | |
(printrireki (car slist)) | |
(inner-solve (nconc (cdr slist) (nextnodesforall (car slist) '(0 1 2 3)))))) | |
(defun issolved (node) | |
(equal (node-state node) '(2 3 0 1))) | |
(defun printrireki (node) | |
(print (node-rireki node))) | |
(defun nextnodesforall (node list) | |
(iter (for a in list) | |
(collect | |
(make-node | |
:rireki (append (node-rireki node) (list a)) | |
:state (nextstate (node-state node) a))))) | |
(defun nth1- (list n) | |
(if (= n 0) | |
(cons (1- (car list)) (cdr list)) | |
(cons (car list) (nth1- (cdr list) (1- n))))) | |
(defun nextstate (state move) | |
(mapcar #'(lambda (x) (mod x 4)) (nth1- (mapcar #'1+ state) (mod (1+ move) 4)))) | |
(defun solve (state) | |
(inner-solve (list (make-node :state state)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment