Skip to content

Commit 6ff3796

Browse files
refactor: we can now use the reflective symmetry of forward and
backwards direction to remove duplication.
1 parent 53cc4ae commit 6ff3796

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

lib/planar_map.rb

+1-10
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,7 @@ def self.forwards(location, direction = location.direction)
1616
end
1717

1818
def self.backwards(location, direction = location.direction)
19-
case direction
20-
when 'N'
21-
Location.new(coordinates: Coordinates.new(x: location.x, y: location.y - 1), direction: location.direction)
22-
when 'E'
23-
Location.new(coordinates: Coordinates.new(x: (location.x - 1) % 36, y: location.y), direction: location.direction)
24-
when 'S'
25-
Location.new(coordinates: Coordinates.new(x: location.x, y: location.y + 1), direction: location.direction)
26-
when 'W'
27-
Location.new(coordinates: Coordinates.new(x: (location.x + 1) % 36, y: location.y), direction: location.direction)
28-
end
19+
forwards(location, invert(direction))
2920
end
3021

3122

0 commit comments

Comments
 (0)