From e637ae3e78895499ea47f02cc056b013eaecdd08 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sat, 19 Dec 2015 21:31:39 -0800 Subject: [PATCH] Day 20.1 --- ruby/day_20.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ruby/day_20.rb b/ruby/day_20.rb index 4e037df..53eb28d 100644 --- a/ruby/day_20.rb +++ b/ruby/day_20.rb @@ -1,14 +1,16 @@ -require "prime" +houses = Hash.new(0) -house = 1 +elf = 0 while true - house += 1 + elf += 1 - factors = house.prime_division - presents = factors.map {|f,x| (x+1).times.map {|i| f**i }.inject(:+) }.inject(:*) + 50.times do |i| + house = (i+1)*elf + houses[house] += 11*elf - if presents >= 3600000 - puts house - exit + if i.zero? && houses[house] >= 36000000 + puts house + exit + end end end