Skip to content

Instantly share code, notes, and snippets.

@twfarland
Created November 14, 2012 19:47
Show Gist options
  • Save twfarland/4074309 to your computer and use it in GitHub Desktop.
Save twfarland/4074309 to your computer and use it in GitHub Desktop.
shortest path racket version
#lang racket
(require "../connive/connive.rkt")
;; :: (state -> [state]), (state -> Bool), state -> [state]
(:= (blocking-path get-successors goal? start)
;; :: (set state), [state] -> #f | [state]
(:== solution (blocked path)
(_ (cons (list state info) prevs))
(?? (goal? (list state info)) (reverse path)
(lyt (now-blocked (set-add blocked state))
(first-solution now-blocked path (<- s s (get-successors (list state info))
(not (set-member? now-blocked (first s))))))))
;; :: (set state), [state], [state] -> #f | [state]
(:== first-solution (blocked path states)
(_ _ empty) #f
(_ _ (cons state states)) (or (solution blocked (cons state path))
(first-solution blocked path states)))
(solution (set) (list start)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment