;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-advanced-reader.ss" "lang")((modname |29.3|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))))) (define (find-route1 ori dest G) (local ((define (find-route ori dest G) (cond [(symbol=? ori dest) (list ori)] [else (local ((define possible-route (find-route/list (neighbors ori G) dest G))) (cond [(boolean? possible-route) false] [else (cons ori possible-route)]))])) (define (find-route/list lo-ori dest G) (cond [(empty? lo-ori) false] [else (local ((define possible-route (find-route (first lo-ori) dest G))) (cond [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)] [else possible-route]))])) (define (neighbors anode G) (first (rest (assf (lambda (x) (equal? anode x)) G))))) find-route ori dest G)) (define (neighbors anode agraph) (vector-ref agraph anode)) (define G (vector '(1 4) '(4 5) '(3) empty '(2 5) '(3 6) empty)) ;find-route : node node graph -> (listof nodes) ;Find a route from ori to dest given G and return the route as a (listof nodes). (define (find-route ori dest G) (cond [(= ori dest) (list ori)] [else (local ((define possible-route (find-route/list (neighbors ori G) dest G))) (cond [(boolean? possible-route) false] [else (cons ori possible-route)]))])) ;find-route/list : (listof nodes) node graph -> (listof nodes) ;Find a route from lo-ori (listof nodes) to dest given G and return the route as a (listof nodes). (define (find-route/list lo-ori dest G) (cond [(empty? lo-ori) false] [else (local ((define possible-route (find-route (first lo-ori) dest G))) (cond [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)] [else possible-route]))]))