#!/usr/bin/perl
#
# Compute tables used to illustrate "diary" approach to twin paradox
#

$v = 0.9;
$gamma = 1.0 / sqrt(1.0 - $v*$v);


# first, entries for the planet people
if (0 == 1) {
  for ($i = 0; $i <= 60; $i++) {
  
    $year = $i + 2500;
  
    $age_bob = $i + 20;
    $age_boot = $i + 20;
    $age_joe = ($i / $gamma) + 20;
  
    printf " %8d   %10.2f %10.2f %10.2f \n", 
             $year, $age_bob, $age_joe, $age_bob;
  
  
  }
}

# now, entries for Joe, the traveller.  We treat his journey
#    in several steps

if (1 == 1) {
  for ($i = 0; $i <= 13; $i++) {
  
    $year = $i + 2500;
  
    $age_bob = ($i / $gamma) + 20;
    $age_boot = ($i / $gamma) + ($v*27.0) + 20;
    $age_joe = $i + 20;
  
    printf " %10.2f  %10.2f %10.2f %10.2f \n", 
             $year, $age_bob, $age_joe, $age_boot;
  
  
  }

  {
    # when Joe arrives at P27
    $i = 13.07;

    $year = $i + 2500;
  
    $age_bob = ($i / $gamma) + 20;
    $age_boot = ($i / $gamma) + ($v*27.0) + 20;
    $age_joe = $i + 20;
  
    printf "\n";
    printf " %10.2f  %10.2f %10.2f %10.2f \n", 
             $year, $age_bob, $age_joe, $age_boot;
    printf "\n";
  }

  {
    # when Joe hops onto the Green ship
  $start = 13.07;
  for ($i = $start; $i < 2.0*$start; $i++) {

    $year = ($i - $start) + 2530;
  
    $age_bob = 2.0*($v*27.0) + ($i / $gamma) + 20;
    $age_boot = 50.0 + (($i - $start) / $gamma);
    $age_joe = $i + 20.0;
  
    printf " %10.2f  %10.2f %10.2f %10.2f \n", 
             $year, $age_bob, $age_joe, $age_boot;
  }
  }

  {
    # when Joe returns to Earth, still on the Green ship
  $start = 13.07;
  $i = 2.001*$start;

    $year = $i + (2530 - $start);
  
    $age_bob = 2.0*($v*27.0) + ($i / $gamma) + 20;
    $age_boot = 50.0 + (($i - $start) / $gamma);
    $age_joe = $i + 20.0;
  
    printf " %10.2f  %10.2f %10.2f %10.2f \n", 
             $year, $age_bob, $age_joe, $age_boot;
    printf "\n";
  }


  # Joe steps off the green ship, onto Earth
  {
    $year = 2560.0;
    $age_bob = 80.0;
    $age_joe = 46.15;
    $age_boot = 80.0;

    printf " %10.2f  %10.2f %10.2f %10.2f \n", 
             $year, $age_bob, $age_joe, $age_boot;
  }

}


exit 0;
