Skip to content

Commit

Permalink
Update files
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras committed Mar 13, 2024
1 parent c281e9d commit 39f2baf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
24 changes: 16 additions & 8 deletions exercises/practice/robot-simulator/.meta/example.arr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use context essentials2020
provide-types *

include string-dict
import lists as L

data Axis: axis(label, left, right) end

Expand All @@ -16,21 +17,28 @@ cardinal_axes = [string-dict:
data Robot:
| robot(x :: NumInteger, y :: NumInteger, direction :: String) with:
method move(self, directions :: String) -> Robot:
foldl(
L.foldl(
lam(acc, elt):
direction =
ask:
| elt == 'L' then: cardinal_axes.get-value(self.direction).left
| elt == 'R' then: cardinal_axes.get-value(self.direction).right
| otherwise: self.direction
| elt == 'L' then:
cardinal_axes.get-value(self.direction).left
| elt == 'R' then:
cardinal_axes.get-value(self.direction).right
| otherwise:
self.direction
end
{x; y} =
if elt == 'A':
ask:
| direction == 'north' then: {acc.x; acc.y + 1}
| direction == 'south' then: {acc.x; acc.y - 1}
| direction == 'east' then: {acc.x + 1; acc.y}
| direction == 'west' then: {acc.x - 1; acc.y}
| direction == 'north' then:
{acc.x; acc.y + 1}
| direction == 'south' then:
{acc.x; acc.y - 1}
| direction == 'east' then:
{acc.x + 1; acc.y}
| direction == 'west' then:
{acc.x - 1; acc.y}
end
else:
{acc.x; acc.y}
Expand Down
7 changes: 5 additions & 2 deletions exercises/practice/robot-simulator/robot-simulator.arr
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use context essentials2020
use context essentials2020 # Don't delete this line when using Pyret on Exercism

provide-types *

data Robot:
| robot(x :: NumInteger, y :: NumInteger, direction :: String)
# add your code here
with:
method move(self, directions :: String) -> Robot:
# Add your code here
end
end

0 comments on commit 39f2baf

Please sign in to comment.