100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Summary CSPSC 110 PSET 11 SOLUTION $20.49   Add to cart

Summary

Summary CSPSC 110 PSET 11 SOLUTION

2 reviews
 1261 views  13 purchases
  • Course
  • Institution

CSPSC 110 PSET 11 SOLUTION

Preview 2 out of 9  pages

  • July 11, 2021
  • 9
  • 2020/2021
  • Summary

2  reviews

review-writer-avatar

By: tianrunwan • 2 year ago

review-writer-avatar

By: cuci1129 • 2 year ago

avatar-seller
;; 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 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))))

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller travissmith1. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $20.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

79373 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$20.49  13x  sold
  • (2)
  Add to cart