aboutsummaryrefslogtreecommitdiff
path: root/day11/part2
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2019-10-21 23:44:32 +0100
committerNat Lasseter <user@4574.co.uk>2019-10-21 23:44:32 +0100
commit5534d4e4054f03ac74ff1ab0bd9811aebd5a9aea (patch)
tree9e6ba3c4edb365f7aaf4d20d407f45f2f801442a /day11/part2
parent400c7a256d3f3d41b84889c4c34ea90afb51f730 (diff)
Day11, part1 only
Diffstat (limited to 'day11/part2')
-rw-r--r--day11/part246
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}"