Improve day 2

This commit is contained in:
2021-12-02 11:03:16 +01:00
parent 084205f6d7
commit f4adf8f479
2 changed files with 28 additions and 21 deletions

View File

@@ -3,16 +3,19 @@
depth=0
horizontal=0
while read current; do
if [[ "$current" == "down "* ]]; then
current_tmp=${current/down /}
depth=$((depth+current_tmp))
elif [[ "$current" == "up "* ]]; then
current_tmp=${current/up /}
depth=$((depth-current_tmp))
elif [[ "$current" == "forward "* ]]; then
current_tmp=${current/forward /}
horizontal=$((horizontal+current_tmp))
fi
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))