Day 20.1
change
commit e637ae3e78895499ea47f02cc056b013eaecdd08
author Alpha Chen <alpha.chen@gmail.com>
date
parent ce1fc224
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