xkcd_681.nbt 685 B

12345678910111213141516171819
  1. # Gravity wells
  2. #
  3. # https://xkcd.com/681/
  4. use extra::astronomy
  5. fn well_depth(mass: Mass, radius: Length) -> Length =
  6. G × mass / (g0 × radius) -> km
  7. print("Gravity well depths:")
  8. print("Sun {well_depth(solar_mass, solar_radius):8.0f}")
  9. print("Earth {well_depth(earth_mass, earth_radius):8.0f}")
  10. print("Moon {well_depth(lunar_mass, lunar_radius):8.0f}")
  11. print("Mars {well_depth(mars_mass, mars_radius):8.0f}")
  12. print("Jupiter {well_depth(jupiter_mass, jupiter_radius):8.0f}")
  13. assert_eq(well_depth(earth_mass, earth_radius), 6379 km, 1 km)
  14. assert_eq(well_depth(mars_mass, mars_radius), 1286 km, 3 km)
  15. assert_eq(well_depth(lunar_mass, lunar_radius), 288 km, 1 km)