You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
436 B
21 lines
436 B
3 years ago
|
#!/usr/bin/env bash
|
||
|
|
||
|
file="$1"
|
||
|
|
||
|
horizontal=0
|
||
|
depth=0
|
||
|
|
||
|
while read line; do
|
||
|
direction="$(echo "$line" | cut -d ' ' -f 1)"
|
||
|
amount="$(echo "$line" | cut -d ' ' -f 2)"
|
||
|
case "$direction" in
|
||
|
forward) horizontal=$((horizontal + amount)) ;;
|
||
|
down) depth="$((depth + amount))" ;;
|
||
|
up) depth="$((depth - amount))" ;;
|
||
|
esac
|
||
|
done < <(cat "$file")
|
||
|
|
||
|
echo "Horizontal: $horizontal"
|
||
|
echo "Depth: $depth"
|
||
|
echo "Product: $(( depth * horizontal ))"
|