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

22 lines
403 B
Bash
Executable File

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