3 while read speed duration rest
; do
4 echo "using speed $speed, fly duration $duration, rest duration $rest"
5 s
[$count]=$speed d
[$count]=$duration r
[$count]=$rest points
[$count]=0
7 done < <(sed 's/.*fly //; s,km/s for ,,; s/seconds.*for//; s/ seconds.$//')
8 echo "parsed details on $count racers"
10 # race speed duration rest time # reports distance in $dist for racer at time
12 local speed
=$1 duration
=$2 rest
=$3 limit
=$4
13 dist
=$
((speed
*duration
* (limit
/(duration
+rest
))))
14 tail=$
((limit
%(duration
+rest
)))
15 if [[ $tail -gt $duration ]]; then
16 dist
=$
((dist
+speed
*duration
))
18 dist
=$
((dist
+speed
*tail))
21 # compute time # sets max to max distance, and increments points[$n] of winners
25 while [[ $i -lt ${#s[*]} ]]; do
26 race
${s[i]} ${d[i]} ${r[i]} $1
27 # echo "distance $dist"
28 [[ $dist -gt $max ]] && max
=$dist
32 while [[ $i -lt ${#s[*]} ]]; do
33 race
${s[i]} ${d[i]} ${r[i]} $1
34 [[ $dist == $max ]] && : $
((points
[i
]++))
39 while [[ $i -lt $limit ]]; do
40 echo "racing at second $i"
43 echo "furthest racer at end: $max"
46 while [[ $i -lt ${#s[*]} ]]; do
47 [[ $max -gt ${points[i]} ]] || max
=${points[i]}
50 echo "max points: $max"