Created
December 15, 2015 06:17
-
-
Save jstrube/3d54e15f7d051b72032b to your computer and use it in GitHub Desktop.
adventofcode
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
function santa(current, next) | |
if next == '^' current[1] += 1 | |
elseif next == 'v' current[1] -= 1 | |
elseif next == '<' current[2] += 1 | |
elseif next == '>' current[2] -= 1 | |
else println("not known:", next) end | |
current | |
end | |
#assign variable grid = input from http://adventofcode.com/day/3/input | |
### This solution doesn't work | |
x = Set{ Array{Int64,2}}() | |
start = [0 0] | |
push!(x, start) | |
for i in grid | |
start = santa(start, i) | |
push!(x, start) | |
end | |
println(length(x)) | |
### This solution works! | |
x = Set{ ASCIIString }() | |
start = [0 0] | |
push!(x, string(start)) | |
for i in grid | |
start = santa(start, i) | |
push!(x, string(start)) | |
end | |
println(length(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you rewrite the solution to use tuples, it works too: