aboutsummaryrefslogtreecommitdiff
path: root/day16
diff options
context:
space:
mode:
Diffstat (limited to 'day16')
-rw-r--r--day16/Dockerfile7
-rw-r--r--day16/Makefile14
-rwxr-xr-xday16/entrypoint13
-rw-r--r--day16/input1
-rwxr-xr-xday16/part125
-rwxr-xr-xday16/part227
6 files changed, 87 insertions, 0 deletions
diff --git a/day16/Dockerfile b/day16/Dockerfile
new file mode 100644
index 0000000..e5adcb1
--- /dev/null
+++ b/day16/Dockerfile
@@ -0,0 +1,7 @@
+FROM ruby:2.6.5-slim
+
+WORKDIR /opt
+
+COPY . .
+
+ENTRYPOINT ["./entrypoint"]
diff --git a/day16/Makefile b/day16/Makefile
new file mode 100644
index 0000000..3fa0b2f
--- /dev/null
+++ b/day16/Makefile
@@ -0,0 +1,14 @@
+DAY = 16
+
+.PHONY: run clean
+
+run: build
+ docker run -it --rm aoc2019day$(DAY)
+
+build: part* input
+ docker build -t aoc2019day$(DAY) .
+ touch build
+
+clean:
+ docker image rm -f aoc2019day$(DAY)
+ rm -f build
diff --git a/day16/entrypoint b/day16/entrypoint
new file mode 100755
index 0000000..8982d21
--- /dev/null
+++ b/day16/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/day16/input b/day16/input
new file mode 100644
index 0000000..9ff4c8f
--- /dev/null
+++ b/day16/input
@@ -0,0 +1 @@
+59773590431003134109950482159532121838468306525505797662142691007448458436452137403459145576019785048254045936039878799638020917071079423147956648674703093863380284510436919245876322537671069460175238260758289779677758607156502756182541996384745654215348868695112673842866530637231316836104267038919188053623233285108493296024499405360652846822183647135517387211423427763892624558122564570237850906637522848547869679849388371816829143878671984148501319022974535527907573180852415741458991594556636064737179148159474282696777168978591036582175134257547127308402793359981996717609700381320355038224906967574434985293948149977643171410237960413164669930
diff --git a/day16/part1 b/day16/part1
new file mode 100755
index 0000000..f9bbd52
--- /dev/null
+++ b/day16/part1
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+
+BASE = [0, 1, 0, -1]
+
+input = $stdin.readlines[0].strip.chars.map(&:to_i)
+
+def get_base(n = 1, l = 0)
+ rbase = BASE.map { |b|
+ [b] * n
+ }.flatten
+ t = ((l + 1) / rbase.length) + 1
+ (rbase * t)[1..l]
+end
+
+l = input.length
+100.times do
+ newinput = []
+ l.times do |i|
+ newinput[i] = input.zip(get_base(i+1, l))
+ .map{|a, b| a * b}.sum.abs % 10
+ end
+ input = newinput
+end
+
+puts input.join[0...8]
diff --git a/day16/part2 b/day16/part2
new file mode 100755
index 0000000..653822e
--- /dev/null
+++ b/day16/part2
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+
+BASE = [0, 1, 0, -1]
+
+input = $stdin.readlines[0].strip.chars.map(&:to_i) * 10000
+
+o = input[0...7].join.to_i
+
+def get_base(n = 1, l = 0)
+ rbase = BASE.map { |b|
+ [b] * n
+ }.flatten
+ t = ((l + 1) / rbase.length) + 1
+ (rbase * t)[1..l]
+end
+
+l = input.length
+100.times do
+ newinput = []
+ l.times do |i|
+ newinput[i] = input.zip(get_base(i+1, l)).map{|a, b| a * b}.sum.abs % 10
+ end
+ input = newinput
+end
+
+
+puts input.join[o...(o+8)]