-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
20 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
data/scenarios/Testing/144-subworlds/_subworld-robots/judges.sw
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
def getRobotNumber = \n. | ||
r <- robotnumbered n; | ||
if (r == self) { | ||
return n; | ||
} {getRobotNumber $ n + 1}; | ||
end; | ||
|
||
def amLowestRecursive = \targetName. \idx. | ||
r <- robotnumbered idx; | ||
thisName <- as r {whoami}; | ||
if (thisName == targetName) { | ||
return $ r == self; | ||
} {amLowestRecursive targetName $ idx + 1}; | ||
end; | ||
|
||
/** | ||
Iterates through robots by increasing index. | ||
If we encounter a robot, fetched by index, | ||
with the same name as me, but I am not that robot, | ||
then we return false. | ||
*/ | ||
def amFirstOfMyName = | ||
myName <- whoami; | ||
amLowestRecursive myName 0; | ||
end; | ||
|
||
def waitToGiveThing = \thing. | ||
r <- meet; | ||
case r (\_. wait 1; waitToGiveThing thing) $ \b. give b thing; | ||
end; | ||
|
||
def waitToGive = | ||
let thing = "bitcoin" in | ||
create thing; | ||
waitToGiveThing thing; | ||
end; | ||
|
||
def waitToReceive = | ||
noop; | ||
end; | ||
|
||
def go = | ||
myNumber <- getRobotNumber 0; | ||
log $ "My number: " ++ format myNumber; | ||
amFirst <- amFirstOfMyName; | ||
log $ "Am first with this name? " ++ format amFirst; | ||
|
||
if amFirst {waitToReceive} {waitToGive}; | ||
end; | ||
|
||
go; |
8 changes: 8 additions & 0 deletions
8
data/scenarios/Testing/144-subworlds/_subworld-robots/solution.sw
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end; | ||
|
||
doN 16 move; | ||
|
||
r <- meet; | ||
case r return $ \j. give j "bitcoin"; | ||
|
This file contains 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
This file contains 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
This file contains 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