Question: ( @htdf find - path ) ( @signature String String Map - > ( listof String ) or false ) ;; try to find path
@htdf findpath
@signature String String Map listof String or false
;; try to find path between from and to while enforcing door lock rules
;define findpath start to castle false ;stub
define findpath start to castle
;; path is listof String the path from start to the current room
;; keygained is listof Natural the keys that gain so far
local define fnforroom r path keygained
cond string to roomname r toappend path list to
memberroomname r path false
else
fnforlos roomexits r
append path list roomname r
append roomkeys r keygained
define fnforlos los path keygained
cond empty los false
else
local define approvedlos realexits los keygained
define try fnforroom
generateroom
first approvedlos castle
path
keygained
if not false try
try
fnforlos rest approvedlos
path keygained
define realexits rooms keys
local define fn r
allinroomlocks generateroom r castle keys
filter fn rooms
define allin locs keys
andmap lambda nmember n keys locs
if not emptyroomlocks generateroom start castle false
fnforroom generateroom start castle empty
empty
@problem
;;
;; Convert the function above to use tail recursion. Call this new function
;; findpathtr so that the grader can test both versions.
;;
;; HINT: You will need worklists working together in tandem
;;
@htdf findpathtr
@signature String String Map listof String or false
;; try to find path between from and to while enforcing door lock rules
checkexpect findpathtr AB MAP false
checkexpect findpathtr AD MAP false
checkexpect findpathtr CE MAP false
;define findpathtr start to castle false ;stub
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
