aboutsummaryrefslogtreecommitdiff
path: root/day11/part2
blob: 9952ea14a1f302eedd6721698fd8a0f6bba8fa8c (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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}"