32 lines
644 B
Bash
32 lines
644 B
Bash
|
#!/usr/bin/env bash
|
||
|
|
||
|
set -o errexit
|
||
|
set -o nounset
|
||
|
set -o pipefail
|
||
|
if [[ "${TRACE-0}" == "1" ]]; then
|
||
|
set -o xtrace
|
||
|
fi
|
||
|
|
||
|
cd "$(dirname "$0")"
|
||
|
|
||
|
INPUT="$1"
|
||
|
|
||
|
main ()
|
||
|
{
|
||
|
time_record=$(grep Time "${INPUT}" | cut -d : -f 2 | tr -d ' ')
|
||
|
distance_record=$(grep Distance "${INPUT}" | cut -d : -f 2 | tr -d ' ')
|
||
|
for ((t=1; t<time_record; t++)); do
|
||
|
t_remaining=$((time_record-t))
|
||
|
distance=$((t*t_remaining))
|
||
|
if [[ ${distance} -gt ${distance_record} ]]; then
|
||
|
first_winning="${t}"
|
||
|
last_winning=$((time_record-first_winning))
|
||
|
winning=$((last_winning-first_winning+1))
|
||
|
break
|
||
|
fi
|
||
|
done
|
||
|
echo "${winning}"
|
||
|
}
|
||
|
|
||
|
main
|