Day zero - bash

This commit is contained in:
Logan Hunt 2022-12-01 00:00:23 -07:00
commit 20c0e48fcc
Signed by untrusted user who does not match committer: simponic
GPG Key ID: 52B3774857EB24B1
28 changed files with 64 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*/input
*.swp

21
README.md Normal file
View File

@ -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

0
day-0/.gitkeep Normal file
View File

40
day-0/sol.sh Executable file
View File

@ -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)"

0
day-1/.gitkeep Normal file
View File

0
day-10/.gitkeep Normal file
View File

0
day-11/.gitkeep Normal file
View File

0
day-12/.gitkeep Normal file
View File

0
day-13/.gitkeep Normal file
View File

0
day-14/.gitkeep Normal file
View File

0
day-15/.gitkeep Normal file
View File

0
day-16/.gitkeep Normal file
View File

0
day-17/.gitkeep Normal file
View File

0
day-18/.gitkeep Normal file
View File

0
day-19/.gitkeep Normal file
View File

0
day-2/.gitkeep Normal file
View File

0
day-20/.gitkeep Normal file
View File

0
day-21/.gitkeep Normal file
View File

0
day-22/.gitkeep Normal file
View File

0
day-23/.gitkeep Normal file
View File

0
day-24/.gitkeep Normal file
View File

0
day-3/.gitkeep Normal file
View File

0
day-4/.gitkeep Normal file
View File

0
day-5/.gitkeep Normal file
View File

0
day-6/.gitkeep Normal file
View File

0
day-7/.gitkeep Normal file
View File

0
day-8/.gitkeep Normal file
View File

0
day-9/.gitkeep Normal file
View File