diff options
Diffstat (limited to 'day11/part2')
-rw-r--r-- | day11/part2 | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/day11/part2 b/day11/part2 new file mode 100644 index 0000000..9952ea1 --- /dev/null +++ b/day11/part2 @@ -0,0 +1,46 @@ +#!/usr/bin/env ruby + +require 'ostruct' + +input = $stdin.readlines.map(&:strip)[0].to_i + +grid = Array.new(300) { Array.new(300, 0) } + +300.times { |i| + 300.times { |j| + x = i + 1 + y = j + 1 + r = x + 10 + p = r * y + p += input + p *= r + p = (p / 100) % 10 + p -= 5 + grid[i][j] = p + } +} + +max = OpenStruct.new({x: 0, y: 0, s: 0, p: 0}) + +300.times { |s| + puts s + (300 - s).times { |x| + (300 - s).times { |y| + p = 0 + (s + 1).times { |i| + (s + 1).times { |j| + p += grid[x+i][y+j] + } + } + + if p > max.p then + max.p = p + max.x = x + 1 + max.y = y + 1 + max.s = s + 1 + end + } + } +} + +puts "#{max.x},#{max.y},#{max.s}" |