about summary refs log tree commit diff
path: root/day20.rb
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-12-20 17:39:49 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2015-12-20 17:39:49 +0100
commit67faf96ffc32e8498bb7f90499bcc3e47fb7e0a3 (patch)
tree4b02b7b2096d1ba7cf4b2fa63d61226eaead66c6 /day20.rb
parentbff8b596a3a6ff4b363801fa058f1f35bc328ecf (diff)
downloadadventofcode2015-67faf96ffc32e8498bb7f90499bcc3e47fb7e0a3.tar.gz
adventofcode2015-67faf96ffc32e8498bb7f90499bcc3e47fb7e0a3.tar.xz
adventofcode2015-67faf96ffc32e8498bb7f90499bcc3e47fb7e0a3.zip
day20
Diffstat (limited to 'day20.rb')
-rw-r--r--day20.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/day20.rb b/day20.rb
new file mode 100644
index 0000000..c45c4ff
--- /dev/null
+++ b/day20.rb
@@ -0,0 +1,26 @@
+M = 33100000
+L = 1000000
+
+a = Array.new(L+1, 0)
+mj = 1_0000_0000
+
+1.upto(L) { |i|
+  i.step(L, i) { |j|
+    a[j] += 10*i
+    mj = [mj, j].min  if a[j] >= M
+  }
+}
+p mj
+
+a = Array.new(L+1, 0)
+mj = 1_0000_0000
+
+1.upto(L) { |i|
+  0.upto(50) { |jj|
+    j = i+i*jj
+    break if j > L
+    a[j] += 11*i
+    mj = [mj, j].min  if a[j] >= M
+  }
+}
+p mj