Last active
July 29, 2017 10:59
-
-
Save hieunguyentrung/2738fbcf48f37d4704a0943153fd1c24 to your computer and use it in GitHub Desktop.
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
def dirReduc(arr) | |
dir = {"NORTH" => "SOUTH", "SOUTH" => "NORTH", "WEST" => "EAST", "EAST" => "WEST"} | |
length = arr.length | |
result = [] | |
arr.each do |w| | |
if result.last != dir[w] | |
result << w | |
else | |
result.pop | |
end | |
end | |
result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment