aboutsummaryrefslogtreecommitdiff
path: root/day17.rb
blob: 465b485d75c4a23a75b438df0d535fdece41d435 (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
27
28
29
d = File.readlines("day17").map { |x| x.to_i }
t = 150

d.sort!

$c = 0
$cs = Hash.new(0)

def r(u, s, a, t)
  if s == t
    p u
    $c += 1
    $cs[u.size] += 1
  elsif s > t
    # too high
  else
    a.each_index { |i|
      r(u + [a[i]], s+a[i], a[i+1..-1], t)
    }
  end
end

p d

r([], 0, d, t)
p $c
p $cs

# 313265 too high