🎉」 init(2025): day 1

This commit is contained in:
2025-12-01 11:25:06 +01:00
commit 6306ab23d1
52 changed files with 2012 additions and 0 deletions

24
2024/day01/part1.sh Executable file
View File

@@ -0,0 +1,24 @@
if test -f cleaned_input.txt; then
INPUT=$(cat cleaned_input.txt)
else
INPUT="3 4\n4 3\n2 5\n1 3\n3 9\n3 3"
fi
L1=$(printf "%b" "$INPUT" | awk '{print $1}' | sort -n)
L2=$(printf "%b" "$INPUT" | awk '{print $2}' | sort -n)
L1_ARRAY=($L1)
L2_ARRAY=($L2)
SUM=0
for i in ${!L1_ARRAY[@]}; do
DIFF=$(( ${L1_ARRAY[$i]} - ${L2_ARRAY[$i]} ))
DIFF=${DIFF#-} #get absolute value
SUM=$(( $SUM + $DIFF ))
#echo $SUM
done
echo $SUM