22 lines
301 B
Bash
22 lines
301 B
Bash
|
#!/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))
|