aboutsummaryrefslogtreecommitdiff
path: root/day20.rb
blob: c45c4ff9ad42523810d7d62868a26f92fc9f69c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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