From 20c0e48fcc2fe9da67f9ade5cfc870aa4592642a Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Thu, 1 Dec 2022 00:00:23 -0700 Subject: [PATCH] Day zero - bash --- .gitignore | 3 +++ README.md | 21 +++++++++++++++++++++ day-0/.gitkeep | 0 day-0/sol.sh | 40 ++++++++++++++++++++++++++++++++++++++++ day-1/.gitkeep | 0 day-10/.gitkeep | 0 day-11/.gitkeep | 0 day-12/.gitkeep | 0 day-13/.gitkeep | 0 day-14/.gitkeep | 0 day-15/.gitkeep | 0 day-16/.gitkeep | 0 day-17/.gitkeep | 0 day-18/.gitkeep | 0 day-19/.gitkeep | 0 day-2/.gitkeep | 0 day-20/.gitkeep | 0 day-21/.gitkeep | 0 day-22/.gitkeep | 0 day-23/.gitkeep | 0 day-24/.gitkeep | 0 day-3/.gitkeep | 0 day-4/.gitkeep | 0 day-5/.gitkeep | 0 day-6/.gitkeep | 0 day-7/.gitkeep | 0 day-8/.gitkeep | 0 day-9/.gitkeep | 0 28 files changed, 64 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 day-0/.gitkeep create mode 100755 day-0/sol.sh create mode 100644 day-1/.gitkeep create mode 100644 day-10/.gitkeep create mode 100644 day-11/.gitkeep create mode 100644 day-12/.gitkeep create mode 100644 day-13/.gitkeep create mode 100644 day-14/.gitkeep create mode 100644 day-15/.gitkeep create mode 100644 day-16/.gitkeep create mode 100644 day-17/.gitkeep create mode 100644 day-18/.gitkeep create mode 100644 day-19/.gitkeep create mode 100644 day-2/.gitkeep create mode 100644 day-20/.gitkeep create mode 100644 day-21/.gitkeep create mode 100644 day-22/.gitkeep create mode 100644 day-23/.gitkeep create mode 100644 day-24/.gitkeep create mode 100644 day-3/.gitkeep create mode 100644 day-4/.gitkeep create mode 100644 day-5/.gitkeep create mode 100644 day-6/.gitkeep create mode 100644 day-7/.gitkeep create mode 100644 day-8/.gitkeep create mode 100644 day-9/.gitkeep 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