From 9ddf2aad708638e321c726b7375352d5a4d66249 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 13 Dec 2015 09:43:15 -0800 Subject: [PATCH] Day 13.1 --- day_13.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/day_13.rb b/day_13.rb index 74297f0..30845e2 100644 --- a/day_13.rb +++ b/day_13.rb @@ -1,10 +1,11 @@ regex = /(\w+) would (\w+) (\d+) happiness units by sitting next to (\w+)/ -happiness = Hash.new {|h,k| h[k] = {} } +happiness = Hash.new {|h,k| h[k] = Hash.new(0) } DATA.read.scan(regex).each do |left, sign, units, right| units = units.to_i units *= (sign == "gain") ? 1 : -1 happiness[left][right] = units end +happiness["Alpha"] = Hash.new(0) puts happiness.keys.permutation.map { |arrangement| arrangement << arrangement.first