aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--day01/Dockerfile7
-rw-r--r--day01/Makefile13
-rwxr-xr-xday01/entrypoint13
-rw-r--r--day01/input100
-rwxr-xr-xday01/part15
-rwxr-xr-xday01/part215
6 files changed, 153 insertions, 0 deletions
diff --git a/day01/Dockerfile b/day01/Dockerfile
new file mode 100644
index 0000000..e5adcb1
--- /dev/null
+++ b/day01/Dockerfile
@@ -0,0 +1,7 @@
+FROM ruby:2.6.5-slim
+
+WORKDIR /opt
+
+COPY . .
+
+ENTRYPOINT ["./entrypoint"]
diff --git a/day01/Makefile b/day01/Makefile
new file mode 100644
index 0000000..b5b7219
--- /dev/null
+++ b/day01/Makefile
@@ -0,0 +1,13 @@
+DAY = 01
+
+.PHONY: run clean
+
+run: build
+ docker run -it --rm aoc2019day$(DAY)
+
+build: part* input
+ docker build -t aoc2019day$(DAY) .
+ touch build
+
+clean:
+ rm -f build
diff --git a/day01/entrypoint b/day01/entrypoint
new file mode 100755
index 0000000..8982d21
--- /dev/null
+++ b/day01/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/day01/input b/day01/input
new file mode 100644
index 0000000..b72d1ab
--- /dev/null
+++ b/day01/input
@@ -0,0 +1,100 @@
+138486
+133535
+66101
+98143
+56639
+120814
+142212
+92654
+100061
+104095
+55169
+94082
+76014
+81109
+106237
+111930
+138463
+145843
+142133
+71154
+112809
+136465
+142342
+68794
+131804
+146345
+107935
+98577
+127456
+89612
+95710
+149792
+136982
+92773
+92303
+114637
+107447
+111815
+149603
+106822
+78811
+114120
+148773
+90259
+101612
+82220
+139301
+91121
+99366
+84070
+120713
+59311
+120435
+56106
+127426
+110465
+76167
+81199
+116298
+110064
+125674
+135698
+86792
+114228
+119794
+76683
+125698
+103450
+142435
+142297
+122593
+96177
+104287
+121379
+54729
+108057
+127334
+91718
+67009
+93304
+66907
+133910
+145775
+119241
+117492
+56351
+96171
+50449
+137815
+149308
+119003
+60320
+66853
+56648
+52003
+115137
+124759
+73799
+94731
+147480
diff --git a/day01/part1 b/day01/part1
new file mode 100755
index 0000000..6d82338
--- /dev/null
+++ b/day01/part1
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+input = $stdin.readlines.map(&:strip).map(&:to_i)
+
+puts input.map{ |x| (x / 3) - 2 }.sum
diff --git a/day01/part2 b/day01/part2
new file mode 100755
index 0000000..6f70fe7
--- /dev/null
+++ b/day01/part2
@@ -0,0 +1,15 @@
+#!/usr/bin/env ruby
+
+def fuel_required(mass)
+ fuel_queue = [mass]
+
+ loop do
+ new_fuel = (fuel_queue.last / 3) - 2
+ return (fuel_queue.sum - mass) if new_fuel <= 0
+ fuel_queue << new_fuel
+ end
+end
+
+input = $stdin.readlines.map(&:strip).map(&:to_i)
+
+puts input.map{ |x| fuel_required(x) }.sum