Physics Scenarios
alias BetterThanNASA.Physics
alias BetterThanNASA.MissionControl
Mission Metadata
mission_metadata = %{
planets: MissionControl.list_planets(),
operations: MissionControl.list_operations(),
earth_gravity: MissionControl.gravity_for(:earth)
}
mission_metadata
%{operations: [:launch, :landing], planets: [:earth, :moon, :mars], earth_gravity: 9.807}
Successful Calculation
apollo_11_csm_landing = Physics.calculate_fuel(28_801, :landing, :earth)
IO.puts("Apollo 11 CSM Landing Fuel: #{apollo_11_csm_landing} kg")
Apollo 11 CSM Landing Fuel: 13447 kg
:ok
Not Enough Fuel
try do
Physics.calculate_fuel(1, :landing, :moon)
rescue
error ->
IO.puts("ArithmeticError: #{error.message}")
end
ArithmeticError: not enough fuel
:ok
Quick Comparison
%{
mission_metadata: mission_metadata,
apollo_11_landing_fuel: apollo_11_csm_landing
}
%{
mission_metadata: %{
operations: [:launch, :landing],
planets: [:earth, :moon, :mars],
earth_gravity: 9.807
},
apollo_11_landing_fuel: 13447
}