Improve day 2
This commit is contained in:
11
02/01.sh
11
02/01.sh
@@ -3,16 +3,19 @@
|
|||||||
depth=0
|
depth=0
|
||||||
horizontal=0
|
horizontal=0
|
||||||
while read current; do
|
while read current; do
|
||||||
if [[ "$current" == "down "* ]]; then
|
case "$current" in
|
||||||
|
"down "*)
|
||||||
current_tmp=${current/down /}
|
current_tmp=${current/down /}
|
||||||
depth=$((depth+current_tmp))
|
depth=$((depth+current_tmp))
|
||||||
elif [[ "$current" == "up "* ]]; then
|
;;
|
||||||
|
"up "*)
|
||||||
current_tmp=${current/up /}
|
current_tmp=${current/up /}
|
||||||
depth=$((depth-current_tmp))
|
depth=$((depth-current_tmp))
|
||||||
elif [[ "$current" == "forward "* ]]; then
|
;;
|
||||||
|
"forward "*)
|
||||||
current_tmp=${current/forward /}
|
current_tmp=${current/forward /}
|
||||||
horizontal=$((horizontal+current_tmp))
|
horizontal=$((horizontal+current_tmp))
|
||||||
fi
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
echo $((depth*horizontal))
|
echo $((depth*horizontal))
|
||||||
|
|||||||
12
02/02.sh
12
02/02.sh
@@ -4,17 +4,21 @@ aim=0
|
|||||||
depth=0
|
depth=0
|
||||||
horizontal=0
|
horizontal=0
|
||||||
while read current; do
|
while read current; do
|
||||||
if [[ "$current" == "down "* ]]; then
|
case "$current" in
|
||||||
|
"down "*)
|
||||||
current_tmp=${current/down /}
|
current_tmp=${current/down /}
|
||||||
aim=$((aim+current_tmp))
|
aim=$((aim+current_tmp))
|
||||||
elif [[ "$current" == "up "* ]]; then
|
;;
|
||||||
|
"up "*)
|
||||||
current_tmp=${current/up /}
|
current_tmp=${current/up /}
|
||||||
aim=$((aim-current_tmp))
|
aim=$((aim-current_tmp))
|
||||||
elif [[ "$current" == "forward "* ]]; then
|
;;
|
||||||
|
"forward "*)
|
||||||
current_tmp=${current/forward /}
|
current_tmp=${current/forward /}
|
||||||
horizontal=$((horizontal+current_tmp))
|
horizontal=$((horizontal+current_tmp))
|
||||||
depth=$((depth+aim*current_tmp))
|
depth=$((depth+aim*current_tmp))
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
echo $((depth*horizontal))
|
echo $((depth*horizontal))
|
||||||
|
|||||||
Reference in New Issue
Block a user