Day 2
This commit is contained in:
18
02/01.sh
Executable file
18
02/01.sh
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
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
|
||||||
|
done
|
||||||
|
|
||||||
|
echo $((depth*horizontal))
|
||||||
20
02/02.sh
Executable file
20
02/02.sh
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/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))
|
||||||
Reference in New Issue
Block a user