Created
April 26, 2021 10:27
-
-
Save anastasop/df70b13525ed426c4e1dcd690703ac67 to your computer and use it in GitHub Desktop.
A tree-search for a first grade puzzle
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
#!/usr/bin/sbcl --script | |
(defparameter routes `((A B C) | |
(B A C D) | |
(C A B D E) | |
(D B C E) | |
(E))) | |
(defparameter start 'A) | |
(defparameter finish 'E) | |
(defun terminal (path) (eq finish (first (last path)))) | |
(do ((frontier (list (list start)))) | |
((null frontier)) | |
(let* ((path (pop frontier)) | |
(choices (rest (assoc (first (last path)) routes))) | |
(unvisited (set-difference choices path))) | |
(if (terminal path) | |
(progn (prin1 path) (terpri)) | |
(dolist (visit unvisited) | |
(push (append path (list visit)) frontier))))) |
Author
anastasop
commented
Apr 26, 2021
7 διαφορετικές διαδρομές
(A B C D E)
(A B C E)
(A B D C E)
(A B D E)
(A C B D E)
(A C D E)
(A C E)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment