4 declare -A reverse_orbits
8 while read -u 3 line; do
10 orbit_object=${line#*)}
12 if [ ${orbits[$base_object]+a} ]; then
13 orbits[$base_object]+=",$orbit_object"
15 orbits[$base_object]=$orbit_object
18 if [ ${reverse_orbits[$orbit_object]+a} ]; then
19 reverse_orbits[$orbit_object]+=",$base_object"
21 reverse_orbits[$orbit_object]=$base_object
31 for p in ${orbits[$planet]}; do
32 o=$(get_orbits $p $((indirect+1)))
33 total_orbits=$((total_orbits+$o+$indirect))
44 echo "$start_point $end_point $last_start $offset" >&2
48 if [ ${#orbits[$start_point]} -gt 0 ]; then
49 for p in ${orbits[$start_point]}; do
50 if [ "$p" == "$last_start" ]; then
53 if [ $p == $end_point ]; then
55 if [ $shortest_path -eq -1 ] || [ $offset -lt $shortest_path]; then
56 shortest_path=$((offset))
60 o=$(get_path $p $end_point $start_point $((offset+1)))
62 if [ $shortest_path -eq -1 ] || [ $o -lt $shortest_path ]; then
70 # otherwise, time to check other paths
71 for p in ${reverse_orbits[$start_point]}; do
72 if [ "$p" == "$last_start" ]; then
75 if [ "$p" == "$end_point" ]; then
77 if [ $shortest_path -eq -1 ] || [ $offset -lt $shortest_path]; then
78 shortest_path=$((offset))
82 o=$(get_path $p $end_point $start_point $((offset+1)))
84 if [ $shortest_path -eq -1 ] || [ $o -lt $shortest_path ]; then