master
Dominika 2021-12-02 23:37:09 +01:00
parent 57da860ae4
commit f8ae840a05
2 changed files with 43 additions and 0 deletions

21
2_1.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
a=0
b=0
function num() {
echo $2 # could have used awk, but this works ;p
}
while read line; do
x=$(num $line)
if [[ "$line" == "forward"* ]]; then
a=$((a+x))
elif [[ "$line" == "up"* ]]; then
b=$((b-x))
elif [[ "$line" == "down"* ]]; then
b=$((b+x))
fi
done
echo $((b*a))

22
2_2.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
a=0
c=0
aim=0
function num() {
echo $2 # could have used awk, but this works ;p
}
while read line; do
x=$(num $line)
if [[ "$line" == "forward"* ]]; then
a=$((a+x))
c=$((c+aim*x))
elif [[ "$line" == "up"* ]]; then
aim=$((aim-x))
elif [[ "$line" == "down"* ]]; then
aim=$((aim+x))
fi
done
echo $((c*a))