100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

Summary CPSC 110 - PSET 11 SOLUTIONS

Rating
-
Sold
-
Pages
10
Uploaded on
28-08-2022
Written in
2022/2023

Solutions to CPSC 110 Pset 11

Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Course

Document information

Uploaded on
August 28, 2022
Number of pages
10
Written in
2022/2023
Type
Summary

Subjects

Content preview

;; The first three lines of this file were inserted by DrRacket. They record
metadata
;; about the language level of this file in a form that our tools can easily
process.
#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname pset-11-solution)
(read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-
decimal #f #t none #f () #t)))
;; DO NOT PUT ANYTHING PERSONALLY IDENTIFYING BEYOND YOUR CWL IN THIS FILE.
;; YOUR CWLs WILL BE SUFFICIENT TO IDENTIFY YOU AND, IF YOU HAVE ONE, YOUR
;; PARTNER.
;;
(require spd/tags)

(@assignment psets/pset-11); Do not edit or remove this tag

(@problem 1)

;;
;; Please read through the MODIFIED data definition introduced in Problem Set 6
;; for Treasure that can be found in a Scavenger Hunt. It has been modified
;; to add route durations to travel between treasure boxes.
;;

(@htdd Status)
;; Status is one of:
;; - "buried"
;; - "sunken"
;; - "locked"
;; interp. the status of an unopened treasure box
;;<examples are redundant for enumeration>

(@htdd Treasure)
(define-struct treasure (label amount difficulty status routes))
;; Treasure is (make-treasure String Natural Natural Status (listof Route))
;; interp. a treasure box with a label name,
;; the number of gold coins contained in the treasure box,
;; a rating of difficulty to find and open the treasure box between 1
;; and 5, where 1 is very easy to find and open and 5 is very difficult,
;; the status of the treasure box before it was opened,
;; and a list of routes leading from this treasure box
;; to other treasure boxes

(@htdd Route)
(define-struct route (duration destination))
;; Route is (make-route Natural String)
;; interp. a route leading from one treasure box to another
;; duration is the time in hours it will take to travel to it and
;; destination is the name of the treasure box the route leads to

(define TREASURE-MAP
(list (make-treasure "E" 32 3 "buried" (list (make-route 3 "A")))
(make-treasure "F" 10 2 "locked" (list (make-route 7 "C")))
(make-treasure "B" 6 5 "locked" (list (make-route 9 "E")
(make-route 15 "F")))
(make-treasure "J" 1 1 "sunken" (list (make-route 6 "I")))
(make-treasure "H" 17 2 "sunken" (list (make-route 15 "J")
(make-route 4 "I")))
(make-treasure "G" 52 3 "buried" (list (make-route 2 "D")))
(make-treasure "I" 100 5 "locked" empty)

, (make-treasure "D" 21 1 "sunken" (list (make-route 8 "G")
(make-route 13 "H")
(make-route 9 "I")
(make-route 11 "A")))
(make-treasure "C" 41 4 "buried" (list (make-route 6 "G")))
(make-treasure "A" 7 1 "locked" (list (make-route 12 "B")
(make-route 7 "C")
(make-route 27 "D")))))

;; Consider this to be a primitive function that comes with the data definitions
;; and that given a treasure name it produces the corresponding treasure.
;; Because this consumes a string and generates a treasure calling it will
;; amount to a generative step in a recursion through a graph of treasures and
;; routes. You must not edit this function, but you can experiment with it to
;; see how it works.

;;(@htdf lookup-treasure)
;;(@signature String -> Treasure)
(define (lookup-treasure name)
(local [(define (scan lst)
(cond [(empty? lst) (error "No treasure named " name)]
[else
(if (string=? (treasure-label (first lst)) name)
(first lst)
(scan (rest lst)))]))]
(scan TREASURE-MAP)))

(define TE (lookup-treasure "E"))
(define TF (lookup-treasure "F"))
(define TB (lookup-treasure "B"))
(define TJ (lookup-treasure "J"))
(define TH (lookup-treasure "H"))
(define TG (lookup-treasure "G"))
(define TI (lookup-treasure "I"))
(define TD (lookup-treasure "D"))
(define TC (lookup-treasure "C"))
(define TA (lookup-treasure "A"))




;;
;; These templates traverse a grap with no cycle detection mechanism, so as
;; they appear here they WILL NOT TERMINATE. Any function that uses them
;; must add some appropriate termination guarantee.
;;
(define (fn-for-treasure t)
(local [(define (fn-for-status s)
(cond [(string=? s "buried") (...)]
[(string=? s "sunken") (...)]
[(string=? s "locked") (...)]))

(define (fn-for-treasure t)
(... (treasure-label t)
(treasure-amount t)
(treasure-difficulty t)
(fn-for-status (treasure-status t))
(fn-for-lor (treasure-routes t))))

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
travissmith1 UBC
Follow You need to be logged in order to follow users or courses
Sold
97
Member since
4 year
Number of followers
61
Documents
36
Last sold
1 month ago

3,6

16 reviews

5
6
4
6
3
0
2
0
1
4

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions