diff options
author | Nat Lasseter <user@4574.co.uk> | 2019-10-21 23:44:32 +0100 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2019-10-21 23:44:32 +0100 |
commit | 5534d4e4054f03ac74ff1ab0bd9811aebd5a9aea (patch) | |
tree | 9e6ba3c4edb365f7aaf4d20d407f45f2f801442a /day11 | |
parent | 400c7a256d3f3d41b84889c4c34ea90afb51f730 (diff) |
Day11, part1 only
Diffstat (limited to 'day11')
-rw-r--r-- | day11/Dockerfile | 7 | ||||
-rw-r--r-- | day11/Makefile | 17 | ||||
-rwxr-xr-x | day11/entrypoint | 13 | ||||
-rw-r--r-- | day11/input | 1 | ||||
-rwxr-xr-x | day11/part1 | 46 | ||||
-rw-r--r-- | day11/part2 | 46 |
6 files changed, 130 insertions, 0 deletions
diff --git a/day11/Dockerfile b/day11/Dockerfile new file mode 100644 index 0000000..5e0a8b7 --- /dev/null +++ b/day11/Dockerfile @@ -0,0 +1,7 @@ +FROM ruby:2.5-slim + +WORKDIR /opt + +COPY . . + +ENTRYPOINT ["./entrypoint"] diff --git a/day11/Makefile b/day11/Makefile new file mode 100644 index 0000000..74ebcf8 --- /dev/null +++ b/day11/Makefile @@ -0,0 +1,17 @@ +DAY = 11 + +.PHONY: run clean push + +run: build + docker run -it --rm aoc2018day$(DAY) + +build: part* input + docker build -t aoc2018day$(DAY) . + touch build + +clean: + rm -f build + +push: build + docker tag aoc2018day$(DAY) advent.4574.co.uk/aoc2018day$(DAY) + docker push advent.4574.co.uk/aoc2018day$(DAY) diff --git a/day11/entrypoint b/day11/entrypoint new file mode 100755 index 0000000..8982d21 --- /dev/null +++ b/day11/entrypoint @@ -0,0 +1,13 @@ +#!/bin/bash + +if [ -x part1 ] ; then + echo -ne "Part 1:\n\t" + time ./part1 < input +fi +if [ -x part1 -a -x part2 ] ; then + echo +fi +if [ -x part2 ] ; then + echo -ne "Part 2:\n\t" + time ./part2 < input +fi diff --git a/day11/input b/day11/input new file mode 100644 index 0000000..db39b73 --- /dev/null +++ b/day11/input @@ -0,0 +1 @@ +9995 diff --git a/day11/part1 b/day11/part1 new file mode 100755 index 0000000..dd5ce12 --- /dev/null +++ b/day11/part1 @@ -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, p:0}) + +298.times { |i| + 298.times { |j| + p = 0 + p += grid[i+0][j+0] + p += grid[i+0][j+1] + p += grid[i+0][j+2] + p += grid[i+1][j+0] + p += grid[i+1][j+1] + p += grid[i+1][j+2] + p += grid[i+2][j+0] + p += grid[i+2][j+1] + p += grid[i+2][j+2] + + if p > max.p then + max.p = p + max.x = i + 1 + max.y = j + 1 + end + } +} + +puts "#{max.x},#{max.y}" 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}" |