Files
Exercism/bash/darts/darts.sh
2023-06-18 18:09:09 +02:00

26 lines
500 B
Bash

#!/usr/bin/env bash
x=$1
y=$2
distance=$(echo "sqrt($x^2 + $y^2)" | bc -l)
if [[ $# -ne 2 ]]; then
echo "# there is _some_ output"
exit 1
fi
if ! [[ $x =~ ^[+-]?[0-9]+(\.[0-9]+)?$ ]] || ! [[ $y =~ ^[+-]?[0-9]+(\.[0-9]+)?$ ]]; then
echo "# there is _some_ output"
exit 1
fi
if (( $(echo "$distance > 10" | bc -l) )); then
echo "0"
elif (( $(echo "$distance > 5" | bc -l) )); then
echo "1"
elif (( $(echo "$distance > 1" | bc -l) )); then
echo "5"
else
echo "10"
fi