commit 20c0e48fcc2fe9da67f9ade5cfc870aa4592642a Author: Logan Hunt Date: Thu Dec 1 00:00:23 2022 -0700 Day zero - bash diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6d27dda --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*/input +*.swp + diff --git a/README.md b/README.md new file mode 100644 index 0000000..399d616 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# AOC 2022 + +## Goal Languages + +- [x] BASH + - [Day 0](./day-0) +- [] C +- [] Clojure +- [] Common LISP +- [] C++ +- [] Dart +- [] Elixir +- [] Emacs Lisp +- [] Haskell +- [] Java +- [] JavaScript +- [] Kotlin +- [] PHP +- [] Python +- [] Ruby +- [] TypeScript diff --git a/day-0/.gitkeep b/day-0/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-0/sol.sh b/day-0/sol.sh new file mode 100755 index 0000000..441efb2 --- /dev/null +++ b/day-0/sol.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# USAGE: ./sol.sh (n: top elves) + +NUM_ELVES=${1:-3} + +declare -a ELVES=() +for (( i = 0; i<$NUM_ELVES; i++)) +do + ELVES+=(0) +done + + +add_to_elves () { + local max=$1 + for (( i = 0; i<${NUM_ELVES}; i++)); + do + local tmp="${ELVES[$i]}"; + if [[ $max -ge $tmp ]]; + then + ELVES[$i]=$max + max=$tmp + fi + done +} + +CURRENT_ELF=0 +while read -r line +do + if [[ -z "$line" ]]; + then + add_to_elves $CURRENT_ELF + CURRENT_ELF=0 + else + CURRENT_ELF=$((CURRENT_ELF+line)) + fi +done < input + +echo "MAX ELF = ${ELVES[0]}" +echo "sum(TOP $NUM_ELVES ELVES) = $(printf "%s\n" $(echo "${ELVES[*]}") | paste -sd+ - | bc)" diff --git a/day-1/.gitkeep b/day-1/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-10/.gitkeep b/day-10/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-11/.gitkeep b/day-11/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-12/.gitkeep b/day-12/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-13/.gitkeep b/day-13/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-14/.gitkeep b/day-14/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-15/.gitkeep b/day-15/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-16/.gitkeep b/day-16/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-17/.gitkeep b/day-17/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-18/.gitkeep b/day-18/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-19/.gitkeep b/day-19/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-2/.gitkeep b/day-2/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-20/.gitkeep b/day-20/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-21/.gitkeep b/day-21/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-22/.gitkeep b/day-22/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-23/.gitkeep b/day-23/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-24/.gitkeep b/day-24/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-3/.gitkeep b/day-3/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-4/.gitkeep b/day-4/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-5/.gitkeep b/day-5/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-6/.gitkeep b/day-6/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-7/.gitkeep b/day-7/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-8/.gitkeep b/day-8/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/day-9/.gitkeep b/day-9/.gitkeep new file mode 100644 index 0000000..e69de29