Created
December 3, 2015 09:37
-
-
Save Harxy/50e23e51993f8a304adb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
example_1 = '<v>^^<v^^<><>vvv' | |
co_ord = [[0,0]] | |
last_co_ord = [0,0] | |
array = example_1.split('') | |
array.each do |x| | |
case x | |
when '^' | |
co_ord << [last_co_ord[0]+1, last_co_ord[1]] | |
last_co_ord = [last_co_ord[0]+1, last_co_ord[1]] | |
when 'v' | |
co_ord << [last_co_ord[0]-1, last_co_ord[1]] | |
last_co_ord = [last_co_ord[0]-1, last_co_ord[1]] | |
when '<' | |
co_ord << [last_co_ord[0], last_co_ord[1]+1] | |
last_co_ord = [last_co_ord[0], last_co_ord[1]+1] | |
when '>' | |
co_ord << [last_co_ord[0], last_co_ord[1]-1] | |
last_co_ord = [last_co_ord[0], last_co_ord[1]-1] | |
end | |
end | |
p co_ord.uniq.length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment