Created
October 7, 2021 15:41
-
-
Save byorgey/699f522513c69fe95e96839f5ad684f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A convenient version of if that takes a cmd bool instead of a bool | |
def ifC : forall a. cmd bool -> cmd a -> cmd a -> cmd a = | |
\test. \thn. \els. b <- test; if b thn els | |
end | |
// Do a DFS to harvest trees to the west and north. | |
// Position the robot on a tree near the southeast corner of a | |
// forest for best effect. The robot will collect a bunch | |
// of trees and return to its original starting point. | |
// Capabilities required: recursion, lambdas, scanner | |
def dfs : cmd () = { | |
ifC (ishere "tree") { | |
grab; | |
turn west; | |
ifC blocked {} {move; dfs; turn east; move}; | |
turn north; | |
ifC blocked {} {move; dfs; turn south; move}; | |
} {} | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment