Files
advent-of-code-2021/02/02.sh
2021-12-02 11:03:16 +01:00

25 lines
449 B
Bash
Executable File

#!/bin/bash
aim=0
depth=0
horizontal=0
while read current; do
case "$current" in
"down "*)
current_tmp=${current/down /}
aim=$((aim+current_tmp))
;;
"up "*)
current_tmp=${current/up /}
aim=$((aim-current_tmp))
;;
"forward "*)
current_tmp=${current/forward /}
horizontal=$((horizontal+current_tmp))
depth=$((depth+aim*current_tmp))
;;
esac
done
echo $((depth*horizontal))