100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4.2 TrustPilot
logo-home
Resumen

Summary CPSC 110 - PSET 11 SOLUTIONS

Puntuación
-
Vendido
-
Páginas
10
Subido en
28-08-2022
Escrito en
2022/2023

Solutions to CPSC 110 Pset 11

Institución
Grado









Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.

Escuela, estudio y materia

Grado

Información del documento

Subido en
28 de agosto de 2022
Número de páginas
10
Escrito en
2022/2023
Tipo
Resumen

Temas

Vista previa del contenido

;; 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))))
$18.49
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
travissmith1 UBC
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
97
Miembro desde
4 año
Número de seguidores
61
Documentos
36
Última venta
1 mes hace

3.6

16 reseñas

5
6
4
6
3
0
2
0
1
4

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes