Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To my whom it may concern. I am very new on this platform, would you please tell me what additional information I have to provide

To my whom it may concern. I am very new on this platform, would you please tell me what additional information I have to provide to make it easier for you to understand. Thank you Hi i need help getting these problems solved by using accumulators in DrRacket. Details below before the problems are the data definitions which will be used to solve the problems.

;; 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 ;;

(@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"))

(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))))

(define (fn-for-lor lor) (cond [(empty? lor) (...)] [else (... (fn-for-route (first lor)) (fn-for-lor (rest lor)))]))

(define (fn-for-route r) (... (route-duration r) ;; lookup-treasure is the generative step that makes the whole ;; MR generative (fn-for-treasure (lookup-treasure (route-destination r)))))] (fn-for-treasure t)))

;;(@problem 1) ;; Design a function that consumes a treasure and produces the total amount ;; of gold that can be obtained by opening that treasure, and all treasures ;; reachable from that treasure. ;; ;; Your solution MUST be tail recursive. ;;

(@htdf reachable-gold) uncomment this when you begin problem 1

(@problem 2) ;; ;; Complete the function that lists the label names of all reachable treasure. ;; ;; Your solution MUST be tail recursive. ;;

(@htdf all-labels) (@signature Treasure -> (listof String)) ;; produce the label names of all reachable treasures (check-expect (all-labels TI) (list "I")) (check-expect (all-labels TH) (list "H" "J" "I")) (check-expect (all-labels TA) (list "A" "B" "E" "F" "C" "G" "D" "H" "J" "I"))

;(define (all-labels t) empty) ;stub

(@problem 3) ;; ;; Complete the function that lists the labels names of all reachable treasures ;; when following only routes with a duration less than n hours long. ;; ;; Your solution MUST be tail recursive. ;;

(@htdf short-dur-reachable) (@signature Treasure Number -> (listof String)) ;; produce labels of all treasures reachable by following routes < n hr long (check-expect (short-dur-reachable TI 12) (list "I")) (check-expect (short-dur-reachable TH 4) (list "H")) (check-expect (short-dur-reachable TH 5) (list "H" "I")) (check-expect (short-dur-reachable TH 16) (list "H" "J" "I")) (check-expect (short-dur-reachable TA 9) (list "A" "C" "G" "D")) ;(define (short-dur-reachable t n) empty) ;stub

(@problem 4) ;; ;; Complete the design of a function that consumes two treasures and counts ;; the number of routes reachable from TE that lead to TF. ;; ;; Note: This is counting the number of routes found in treasure boxes where TF ;; is the destination, NOT the total number of paths between the two treasure ;; boxes. It is asking how many routes have TF as their destination (how many ;; arrows are pointing to TF). ;; ;; Examples: ;; ;; (num-lead-to TA TI) produces 3. This is because there are three routes that ;; are reachable from TA that lead to TI. These routes are the route leading ;; from TH to TI, the route leading from TJ to TI, and the route leading from ;; TD to TI. ;; ;; (num-lead-to TI TA) produces 0. Even though two routes lead to TA (the ;; route from TD to TA and the route from TE to TA), neither route can be ;; reached from TI so the function produces 0. ;; ;; Note that you can use the built-in function equal? to compare if two ;; treasures are equal. For example: ;; - (equal? TE TF) produces false ;; - (equal? TB TB) produces true ;; ;; Your solution MUST be tail recursive. ;;

(@htdf num-lead-to) (@signature Treasure Treasure -> Natural) ;; count the number of reachable routes that lead to TF (check-expect (num-lead-to TI TA) 0) (check-expect (num-lead-to TJ TI) 1) (check-expect (num-lead-to TH TI) 2) (check-expect (num-lead-to TA TI) 3) (check-expect (num-lead-to TF TA) 2) (check-expect (num-lead-to TD TC) 2)

;(define (num-lead-to TE TF) 0) ;stub

(@problem 5) ;; ;; Complete the design of a function that consumes a treasure and the label ;; of another treasure, and produces the time in hours of route durations ;; it would take to travel from t to the treasure labeled s. This function ;; produces the total duration of the routes followed as soon as it finds a ;; treasure labeled s. The function produces false if there is no way of ;; reaching a treasure with the given label. ;;

(@htdf route-to) (@signature Treasure String -> Natural or false) ;; produce the total duration traveled on route to s from t, false if not found (check-expect (route-to TE "X") false) (check-expect (route-to TE "E") 0) (check-expect (route-to TE "A") 3) (check-expect (route-to TH "I") 21) (check-expect (route-to TA "G") 40) (check-expect (route-to TA "J") 70)

;(define (route-to t s) false) ;stub

(@problem 6) ;; ;; Complete the design of a function that consumes a treasure and the label ;; of another treasure, and produces the MINIMUM time in hours of all of the ;; possible routes that could be taken to travel from t to the treasure ;; labeled s. The function produces false if there is no way of reaching the ;; a treasure with the given label. ;;

(@htdf min-route-to) (@signature Treasure String -> Natural or false) ;; produce the min duration traveled on route to s from t, false if not found (check-expect (min-route-to TE "X") false) (check-expect (min-route-to TE "E") 0) (check-expect (min-route-to TE "A") 3) (check-expect (min-route-to TH "I") 4) (check-expect (min-route-to TA "G") 13) (check-expect (min-route-to TA "J") 43)

(define (min-route-to t s) false) ;stub

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intermediate Accounting Reporting And Analysis, 2017 Update

Authors: James M. Wahlen, Jefferson P. Jones, Donald Pagach

2nd Edition

1337505625, 9781337505628

More Books

Students also viewed these Accounting questions

Question

Where do attitudes come from? How do they change?

Answered: 1 week ago

Question

BPR always involves automation. Group of answer choices True False

Answered: 1 week ago

Question

Describe the importance of employer branding.

Answered: 1 week ago

Question

Explain corporate sustainability.

Answered: 1 week ago