CPSC 110 Lecture Notes - Lecture 23: Backtracking

126 views9 pages
Verified Note
26 Nov 2018
School
Course
Professor

Document Summary

;; consider the following visualizations of a rail network. ;; has a name, number of platforms, and is wheelchair accessible or not. ;; - liv has 8 platforms and is wheelchair accessible, while. ;; - crw has 5 platforms and is not wheelchair accessible. ;; let"s start by thinking about how we can represent this information as data: (@htdd station) (define-struct station (name platforms accessible? dests)) ;; station is (make-station string natural boolean (listof station)) ;; interp. a station in a rail-network with name, ; encapsulated template from types: (define (fn-for-station s0) (local [(define (fn-for-station s) ( (station-name s) (station-platforms s) (station-accessible? s) (fn-for-los (station-dests s)))) (define (fn-for-los los) (cond [(empty? los) ] [else ( (fn-for-station (first los)) (fn-for-los (rest los)))]))] (fn-for-station s0))) ; tail recursive template from types with rsf and worklist accumululators: (define (fn-for-station s0) ;; todo is (listof station): worklist accumulator; stations to visit (local [(define (fn-for-station s todo rsf)

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers