diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2015-12-15 15:14:32 +0100 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2015-12-15 15:14:32 +0100 |
commit | 2c7509233aebb59f2168b27e3d704dc0d6ad725f (patch) | |
tree | d5ae578ba6602f34a1c3e0b95f5a9006c222f10d /day15.rb | |
parent | e8ee73c2b058529ee427f89e388dc012bc354fbb (diff) | |
download | adventofcode2015-2c7509233aebb59f2168b27e3d704dc0d6ad725f.tar.gz adventofcode2015-2c7509233aebb59f2168b27e3d704dc0d6ad725f.tar.xz adventofcode2015-2c7509233aebb59f2168b27e3d704dc0d6ad725f.zip |
day15
Diffstat (limited to 'day15.rb')
-rw-r--r-- | day15.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/day15.rb b/day15.rb new file mode 100644 index 0000000..fdf4ab8 --- /dev/null +++ b/day15.rb @@ -0,0 +1,35 @@ +d = File.readlines("day15") + +sc = [] + +(1..100).to_a.repeated_permutation(d.size-1) { |z| + r = 100 - z.inject(:+) + if r > 0 + z = z+[r] + + p d.map.with_index { |line,i| [z[i], line.split[2].to_i] } + + x = [2,4,6,8].map { |f| + v = 0 + d.each.with_index { |line, i| + v += z[i] * line.split[f].to_i + } + [v,0].max + } + + c = 0 + d.each.with_index { |line, i| + c += z[i] * line.split[10].to_i + } + + next unless c == 500 + + p [:YES, x] if x[0] != 0 + if x.inject(:*) > 0 + sc << x.inject(:*) + p sc.last + end + end +} + +p sc.max |