7 declare -A reverse_orbits
 
  11 while read -u 3 line; do
 
  12     base_object=${line%)*}
 
  13     orbit_object=${line#*)}
 
  15     if [ ${orbits[$base_object]+a} ]; then
 
  16         orbits[$base_object]+=",$orbit_object"
 
  18         orbits[$base_object]=$orbit_object
 
  21     if [ ${reverse_orbits[$orbit_object]+a} ]; then
 
  22         reverse_orbits[$orbit_object]+=",$base_object"
 
  24         reverse_orbits[$orbit_object]=$base_object
 
  34     if [ ${orbits[$planet]+a} ]; then
 
  35         for p in ${orbits[$planet]}; do
 
  36             o=$(get_orbits $p $((indirect+1)))
 
  37             total_orbits=$((total_orbits+$o+$indirect))
 
  48     local path=${5:-$start_point}
 
  49     local shortest_path=-1
 
  50     local shortest_path_text=""
 
  56     if [ ${orbits[$start_point]+a} ]; then
 
  57         for p in ${orbits[$start_point]}; do
 
  58             if [ "$p" == "$last_start" ]; then
 
  61             if [ $p == $end_point ]; then
 
  63                 shortest_path_text="$path $p"
 
  64                 echo $((shortest_path - 1))
 
  67                 o="$(get_path $p $end_point $start_point $((offset+1)) "$path $p")"
 
  69                 if [ $exit_code -eq 0 ]; then
 
  70                     if [ $shortest_path -eq -1 ] || [ $o -lt $shortest_path ]; then
 
  72                         shortest_path_text="$path $p"
 
  80     if [ $got_path -eq 1 ]; then
 
  85     # otherwise, time to check other paths
 
  86     if [ ${reverse_orbits[$start_point]+a} ]; then
 
  87         for p in ${reverse_orbits[$start_point]}; do
 
  88             if [ "$p" == "$last_start" ]; then
 
  91             if [ "$p" == "$end_point" ]; then
 
  93                 shortest_path_text="$path $p"
 
  94                 echo $((shortest_path - 1))
 
  97                 o="$(get_path $p $end_point $start_point $((offset+1)) "$path $p")"
 
  99                 if [ $exit_code -eq 0 ]; then
 
 100                     if [ $shortest_path -eq -1 ] || [ $o -lt $shortest_path ]; then
 
 102                         shortest_path_text="$path $p"
 
 110     if [ $got_path -eq 1 ]; then
 
 123 path=$(get_path YOU SAN "")
 
 124 echo "Shortest path from YOU -> SAN: $path"