Skip to content

Instantly share code, notes, and snippets.

@anastasop
Created April 26, 2021 10:27
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 anastasop/df70b13525ed426c4e1dcd690703ac67 to your computer and use it in GitHub Desktop.
Save anastasop/df70b13525ed426c4e1dcd690703ac67 to your computer and use it in GitHub Desktop.
A tree-search for a first grade puzzle
#!/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)))))
@anastasop
Copy link
Author

Ez0kXn9WUAEPJ69

@anastasop
Copy link
Author

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