aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--day18/Dockerfile7
-rw-r--r--day18/Makefile17
-rwxr-xr-xday18/entrypoint13
-rw-r--r--day18/input50
-rwxr-xr-xday18/part154
5 files changed, 141 insertions, 0 deletions
diff --git a/day18/Dockerfile b/day18/Dockerfile
new file mode 100644
index 0000000..5e0a8b7
--- /dev/null
+++ b/day18/Dockerfile
@@ -0,0 +1,7 @@
+FROM ruby:2.5-slim
+
+WORKDIR /opt
+
+COPY . .
+
+ENTRYPOINT ["./entrypoint"]
diff --git a/day18/Makefile b/day18/Makefile
new file mode 100644
index 0000000..9978cb1
--- /dev/null
+++ b/day18/Makefile
@@ -0,0 +1,17 @@
+DAY = 18
+
+.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/day18/entrypoint b/day18/entrypoint
new file mode 100755
index 0000000..8982d21
--- /dev/null
+++ b/day18/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/day18/input b/day18/input
new file mode 100644
index 0000000..2343711
--- /dev/null
+++ b/day18/input
@@ -0,0 +1,50 @@
+.||....##....|#|#.....|||...|............|......#.
+#....|#|..#....#....|...#.||...||..|||#|..#..|.##.
+.#|##|.#.|#|..|||....#|..|....|.##.#||#.|.#|..|..|
+|...|#.|...#..|...|#.|.#...##....|.||#...|...|...#
+.....|..#||..........###...#.||.###.|..#|#||..|#..
+|||.|##...|.|||#......###....|#.#|...|.#..|.|.|##.
+.......|.####.||##|.##....#............||#..#..|..
+..#|.|....#..|...|||..|...............|.|#..|.||#.
+.||#.#||.|.|.#.#|....#.#|..|.|#|.|.....|.#...|#..#
+......#..|...#....||#.#.#|..#...#.|||||..|#....|#|
+#.#|..#|#||#|||..#...#.........|.|..#...|......|.#
+|....|#..|##.....|...||.#....#......#...|..|#|#..#
+.|##.|...|......##.##.........#.#..|.||........|..
+.#||#.#...|.|.|.#|.#..|.|#..|##.|..|#....##.||....
+...|..|.#........#.|###|.#|...||.#....|..#.....#|.
+........#.###..###.....#....#|#|...#||..|..|....#|
+.|...........||.|...#|..|#....#|.#..|#..|..|.|.|..
+#.#..|.|||....|.....#|#...##.#......|..|..#..#.#|#
+.#|.#.........|.....##|##.#.#...#|...........#|#..
+..##|.|.|.##|.##..|..|...#|#..|.....|.|.#...#...||
+.|||..#.#.|.|#......####.........#|.|.#|.|.|.#.|..
+|#...|.........#.##..|....|....#|...||.#.|...|#.|#
+##.|.#..|#|#|#.|#.|##|..#.|..##.#....##.#...#|.|..
+.||#..#.#....|.#.#..#|.|.#|##|#.#||....#....#...|.
+#...#...|.|||.....#.|.#|..#......#.#...#.#|...|#||
+...##...|.#.##..||..#|.....|....#.##.#.|..|.|#.#.|
+..#..|...#.|..#......||....#.#|..##|.#....#.|.|...
+||.....|..|##.....##......#|.......|##.|.#.|.#.|..
+#|.|...|.|#...|...........#......|......|...#|.#..
+#|###|..#.##.||..#....|####.#.......#|..|...|.....
+........#.|.........#..##.#.#...|.#.....|.|.#.#|#.
+.##.##.#.|#|..#.###|...#....|#.|#.#|#....#.|...|..
+||...#......|||..#.|.||.|.|#..........#...#.|.|..#
+|.....|..|....#|.#|.#...|#..|#|#..#.###.|.....#.#.
+..#...|#..#...|||..###.|#.|..|......|.||....#.....
+.##.#||..#....#.#.|..|.....#...|..#.|....#..##..||
+........#..............#.||.#........|.|...|.|....
+..#.#..##..|.|..|#....||#...|.#...#|..|##..|...##|
+......#|##..#..........#...||.#|.||.|..|..|....|.#
+##..|.##|..#|#|#.|....|.#|..|#.#...#..##|#.##|.|..
+|...#.|.#.#..|..|....|#||...#..#....#..#|.......#.
+....#.###.#.|.....#.|.#.#.#...|.#|#...#|.....|.##.
+#......#..#.|.....||.#..|....|...#|||....|..|#.|..
+..|.#|##...#.#..#|...|........||#.#.#||.|#.#|#...|
+...|.|.#...|.|.....###|#.##|.#.....#|..|#|#|#.|#|.
+.##..|#.#..#....|#....|..|.||.#|..|.|.|.|..#.#.|..
+.#..|.|##||...|......|...#..#|.#....#...#|||...||.
+.|#.#....|#.#|.|....||.||.##|#...#.||.#.......#|..
+#...||.....|.|...|||...||....#..#....||.|#.|...|#.
+...|#..||....|#..|....|...|.||#..||..#.|..##......
diff --git a/day18/part1 b/day18/part1
new file mode 100755
index 0000000..d17faed
--- /dev/null
+++ b/day18/part1
@@ -0,0 +1,54 @@
+#!/usr/bin/env ruby
+
+def adj(arr, r, c)
+ a = []
+
+ a << arr[r-1][c-1] if r > 0 && c > 0
+ a << arr[r-1][c ] if r > 0
+ a << arr[r-1][c+1] if r > 0 && c < 49
+ a << arr[r ][c-1] if c > 0
+ a << arr[r ][c+1] if c < 49
+ a << arr[r+1][c-1] if r < 49 && c > 0
+ a << arr[r+1][c ] if r < 49
+ a << arr[r+1][c+1] if r < 49 && c < 49
+
+ a
+end
+
+now = $stdin.readlines.map(&:strip).map{|x|x.split("")}
+nxt = []
+
+10.times do
+ 50.times do |r|
+ nxtr = []
+ 50.times do |c|
+ a = adj(now, r, c)
+ nxtr << case now[r][c]
+ when "."
+ if a.count("|") >= 3 then
+ "|"
+ else
+ "."
+ end
+ when "|"
+ if a.count("#") >= 3 then
+ "#"
+ else
+ "|"
+ end
+ when "#"
+ if a.count("#") > 0 && a.count("|") > 0 then
+ "#"
+ else
+ "."
+ end
+ end
+ end
+ nxt << nxtr
+ end
+
+ now = nxt
+ nxt = []
+end
+
+puts now.flatten.count("|") * now.flatten.count("#")