commit 954a9118cde8009233a2f74d97b11a6730b1b4f3 Author: eater <=@eater.me> Date: Mon Dec 2 14:42:57 2019 +0100 Initial commit diff --git a/day-1/part-1/input b/day-1/part-1/input new file mode 100644 index 0000000..328b9d8 --- /dev/null +++ b/day-1/part-1/input @@ -0,0 +1,100 @@ +56583 +83363 +127502 +138143 +113987 +147407 +111181 +92655 +79802 +64636 +108805 +148885 +51022 +120002 +52283 +53573 +142374 +143523 +121158 +63332 +63203 +142400 +105515 +140150 +89910 +93081 +129752 +86731 +128755 +134756 +131066 +77990 +77081 +85779 +137271 +72889 +117608 +132442 +115294 +59414 +75495 +79459 +107669 +81496 +144432 +69138 +53410 +71199 +141799 +63964 +110945 +102174 +87697 +88838 +93552 +145531 +54602 +65080 +66865 +139693 +98048 +60409 +88384 +138807 +130854 +75997 +130900 +125974 +129123 +93480 +86042 +128187 +74981 +88144 +96629 +148836 +124473 +57616 +93477 +104174 +97407 +123017 +85408 +64862 +85298 +88142 +62182 +128983 +62981 +124580 +56339 +94335 +125521 +121373 +78777 +125132 +94411 +57789 +97384 +79900 diff --git a/day-1/part-1/main.sh b/day-1/part-1/main.sh new file mode 100755 index 0000000..f963b2f --- /dev/null +++ b/day-1/part-1/main.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +cd "$(dirname "$0")"; + +output=0; +while read nr; do + a=$((nr / 3)); + a=$((a - 2)); + output=$((a + output)); +done < ./input + +echo $output; diff --git a/day-1/part-2/input b/day-1/part-2/input new file mode 100644 index 0000000..328b9d8 --- /dev/null +++ b/day-1/part-2/input @@ -0,0 +1,100 @@ +56583 +83363 +127502 +138143 +113987 +147407 +111181 +92655 +79802 +64636 +108805 +148885 +51022 +120002 +52283 +53573 +142374 +143523 +121158 +63332 +63203 +142400 +105515 +140150 +89910 +93081 +129752 +86731 +128755 +134756 +131066 +77990 +77081 +85779 +137271 +72889 +117608 +132442 +115294 +59414 +75495 +79459 +107669 +81496 +144432 +69138 +53410 +71199 +141799 +63964 +110945 +102174 +87697 +88838 +93552 +145531 +54602 +65080 +66865 +139693 +98048 +60409 +88384 +138807 +130854 +75997 +130900 +125974 +129123 +93480 +86042 +128187 +74981 +88144 +96629 +148836 +124473 +57616 +93477 +104174 +97407 +123017 +85408 +64862 +85298 +88142 +62182 +128983 +62981 +124580 +56339 +94335 +125521 +121373 +78777 +125132 +94411 +57789 +97384 +79900 diff --git a/day-1/part-2/main.sh b/day-1/part-2/main.sh new file mode 100755 index 0000000..eaa6e43 --- /dev/null +++ b/day-1/part-2/main.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +cd "$(dirname "$0")"; + +function calc_requirement() { + local input=$1; + + a=$((input / 3)); + a=$((a - 2)); + + if [ "$a" -gt 0 ]; then + b=$(calc_requirement "$a"); + a=$((a + b)); + else + a=0; + fi + + echo $a; +} + +output=0; +while read nr; do + a=$(calc_requirement "$nr"); + output=$((a + output)); +done < ./input + +echo $output; diff --git a/day-2/input b/day-2/input new file mode 100644 index 0000000..5233427 --- /dev/null +++ b/day-2/input @@ -0,0 +1 @@ +1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,10,19,1,6,19,23,1,13,23,27,1,6,27,31,1,31,10,35,1,35,6,39,1,39,13,43,2,10,43,47,1,47,6,51,2,6,51,55,1,5,55,59,2,13,59,63,2,63,9,67,1,5,67,71,2,13,71,75,1,75,5,79,1,10,79,83,2,6,83,87,2,13,87,91,1,9,91,95,1,9,95,99,2,99,9,103,1,5,103,107,2,9,107,111,1,5,111,115,1,115,2,119,1,9,119,0,99,2,0,14,0 diff --git a/day-2/main.sh b/day-2/main.sh new file mode 100644 index 0000000..c2eb9e5 --- /dev/null +++ b/day-2/main.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +set -e; + +cd "$(dirname "$0")"; + +run_comp() { + IFS="," read -r -a ops < ./input; + + i=0; + ops[1]=$1; + ops[2]=$2; + + while true; do + op="${ops[i]}"; + case "$op" in + 1|2) + inputa="${ops[i+1]}"; + inputb="${ops[i+2]}"; + output="${ops[i+3]}"; + i=$((i + 4)); + a="${ops[inputa]}" + b="${ops[inputb]}" + if [ "$op" -eq "1" ]; then + x=$((a + b)); + else + x=$((a * b)); + fi + ops[output]=$x; + ;; + 99) + break; + ;; + *) + echo "Invalid op: $op"; + exit 1; + ;; + esac + done + echo "${ops[0]}"; +} + +echo "part 1: "; +run_comp 12 2; +echo; +echo "part 2: "; +for noun in $(seq 1 99); do + for verb in $(seq 1 99); do + if [ "$(run_comp $noun $verb)" -eq 19690720 ]; then + echo "$((100 * noun + verb))"; + exit; + fi + done; +done;