23 lines
331 B
Bash
Executable File
23 lines
331 B
Bash
Executable File
#!/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))
|