Files
advent-of-code-2021/02/02.sh
2021-12-02 10:49:38 +01:00

21 lines
467 B
Bash
Executable File

#!/bin/bash
aim=0
depth=0
horizontal=0
while read current; do
if [[ "$current" == "down "* ]]; then
current_tmp=${current/down /}
aim=$((aim+current_tmp))
elif [[ "$current" == "up "* ]]; then
current_tmp=${current/up /}
aim=$((aim-current_tmp))
elif [[ "$current" == "forward "* ]]; then
current_tmp=${current/forward /}
horizontal=$((horizontal+current_tmp))
depth=$((depth+aim*current_tmp))
fi
done
echo $((depth*horizontal))