From 67faf96ffc32e8498bb7f90499bcc3e47fb7e0a3 Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Sun, 20 Dec 2015 17:39:49 +0100 Subject: day20 --- day20.k | 9 +++++++++ day20.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 day20.k create mode 100644 day20.rb diff --git a/day20.k b/day20.k new file mode 100644 index 0000000..654ba49 --- /dev/null +++ b/day20.k @@ -0,0 +1,9 @@ +d:33100000; + +/ takes ages without a good guess. ;) + +e:{10*y*~x!y} +(1+)/[{d>+/e[x]'!x+1};776150] + +e2:{(x<50*y)*11*y*~x!y} +(1+)/[{d>+/e2[x]'!x+1};786235] 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 -- cgit 1.4.1