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]