diff options
| author | turnipgod <m18coppola@gmail.com> | 2026-12-02 16:38:20 -0500 |
|---|---|---|
| committer | turnipgod <m18coppola@gmail.com> | 2026-12-02 16:38:20 -0500 |
| commit | 6ebc21a3626006c3aa280924ad541745511672b6 (patch) | |
| tree | 69ae5b34d45bffc34a4996bf96c5862324d9a927 | |
| download | aoc2026-in-bash-6ebc21a3626006c3aa280924ad541745511672b6.tar.gz aoc2026-in-bash-6ebc21a3626006c3aa280924ad541745511672b6.tar.xz aoc2026-in-bash-6ebc21a3626006c3aa280924ad541745511672b6.zip | |
init commit; days 1 and 2 solutions
Diffstat (limited to '')
| -rwxr-xr-x | day1/solution.sh | 13 | ||||
| -rwxr-xr-x | day2/solution.sh | 29 |
2 files changed, 42 insertions, 0 deletions
diff --git a/day1/solution.sh b/day1/solution.sh new file mode 100755 index 0000000..94c763b --- /dev/null +++ b/day1/solution.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +table=$(cat input.txt | sort | uniq -c | sort) + +most=$(tail -n3 <<< "$table") +least=$(head -n3 <<< "$table") + +calc(){ + awk 'BEGIN { p = 1 } { p *= $2 } END { print p }' +} + +calc <<< "$most" +calc <<< "$least" diff --git a/day2/solution.sh b/day2/solution.sh new file mode 100755 index 0000000..1b14538 --- /dev/null +++ b/day2/solution.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +field='roygbv' + +ops=$(cat input.txt) + +sorted_ops=$( + cat input.txt | + tr 'rvbgyo' '123456' | + grep -o . | + sort | + tr -d '\n' | + tr '123456' 'rvbgyo' +) + +calc() { + local ops=$1 + local pos=0 + for (( i=0; i<${#ops}; i++ )); do + ((pos++)) + while [ "${field:pos%${#field}:1}" != "${ops:i:1}" ]; do + ((pos++)) + done + done + echo $pos +} + +calc "$ops" +calc "$sorted_ops" |
