From 6935393e9c9841f7ae418b235b5c9e0f22418116 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 28 Oct 2019 22:59:09 +0000 Subject: day 18, part2. part2 is just another uninteresting now do it an impossible number of times type puzzle --- day18/Dockerfile | 7 +++++++ day18/Makefile | 17 +++++++++++++++++ day18/entrypoint | 13 +++++++++++++ day18/input | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ day18/part1 | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 141 insertions(+) create mode 100644 day18/Dockerfile create mode 100644 day18/Makefile create mode 100755 day18/entrypoint create mode 100644 day18/input create mode 100755 day18/part1 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("#") -- cgit v1.2.1