Skip to content

Instantly share code, notes, and snippets.

@hieunguyentrung
Last active July 29, 2017 10:59
Show Gist options
  • Save hieunguyentrung/2738fbcf48f37d4704a0943153fd1c24 to your computer and use it in GitHub Desktop.
Save hieunguyentrung/2738fbcf48f37d4704a0943153fd1c24 to your computer and use it in GitHub Desktop.
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