This commit is contained in:
Alexander Munch-Hansen 2017-12-19 02:43:23 +01:00
parent a23330f007
commit 4ff438de36

21
hexagons.rb Normal file
View File

@ -0,0 +1,21 @@
require 'matrix'
input = File.read("input_11.rb").strip.split(",").map(&:to_sym)
HEX_DIRS = {
:n => Vector[0,1,-1], :ne => Vector[-1,1,0],
:se => Vector[-1,0,1], :s => Vector[0,-1,1],
:sw => Vector[1,-1,0], :nw => Vector[1,0,-1]
}
def dist path
path.reduce({:vec => Vector[0,0,0], :lol => 0}) do |mem,step|
mem[:vec]= new = mem[:vec] + HEX_DIRS[step]
mem[:lol] = [new.map(&:abs).sum / 2, mem[:lol]].max
mem
end
end
out = dist input
p out[:vec].map(&:abs).sum / 2, out[:lol]