The gravitational binding energy of a planet is the amount of energy required to separate every tiny piece of it so that no piece will orbit or collide with another piece. For a uniform sphere, Wikipedia gives this formula:
$$E = \frac{3GM^2}{5R}$$
Where G is the gravitational constant (6.672e-11 m3•kg-1•s-2), M is mass, and R is the radius.
I could make this challenge about merely calculating this in Joules (kg•m2•s-2), but… that would be boring. And besides, not everyone understands Joules.
So instead, let's convert it into the following units:
- Kilotons of TNT (4.184 trillion Joules, shorthand
kilotons
) - Hiroshima nuclear weapons (62.76 trillion Joules, shorthand
nukes
) - Hostess™ Twinkies (560,000 Joules, shorthand
twinkies
) - Kilowatt-hours (exactly 3.6 million Joules, shorthand
kWh
) - Kilograms of mass-energy (1 kg mass-energy = 299,792,4582 Joules, shorthand
kg
)
So, take in the following input:
- mass in kilograms
- radius in meters
- one of six distinct inputs representing the unit to use
And output the binding energy in the specified units. Append the shorthand unit to the end of the output.
Rules
- The shorthand for Joules is
J
. - Arbitrary whitespace is allowed, as long as it doesn't split the shorthand unit or the number.
- Scientific notation is allowed, in whatever format your language uses.
- You only need 4 significant figures. Floating points are highly recommended.
- Blah blah shortest answer in bytes.
Test Cases
Generated with this spreadsheet.
Mass (kg) Radius (m) J kilotons nukes twinkies kWh kg
3.302E+23 2440000 1.789E+30 4.275E+17 2.850E+16 3.194E+24 4.969E+23 1.990E+13
4.869E+24 6052000 1.568E+32 3.748E+19 2.499E+18 2.800E+26 4.356E+25 1.745E+15
5.974E+24 6371000 2.242E+32 5.360E+19 3.573E+18 4.004E+26 6.229E+25 2.495E+15
6.419E+23 3390000 4.866E+30 1.163E+18 7.753E+16 8.689E+24 1.352E+24 5.414E+13
1.899E+27 69911000 2.065E+36 4.935E+23 3.290E+22 3.687E+30 5.736E+29 2.298E+19
5.685E+26 58232000 2.222E+35 5.310E+22 3.540E+21 3.968E+29 6.172E+28 2.472E+18
8.683E+25 25360000 1.190E+34 2.845E+21 1.896E+20 2.125E+28 3.306E+27 1.324E+17
1.024E+26 24620000 1.705E+34 4.075E+21 2.717E+20 3.045E+28 4.736E+27 1.897E+17
1.311E+22 1186000 5.801E+27 1.387E+15 9.244E+13 1.036E+22 1.611E+21 6.455E+10
1.989E+30 696300000 2.274E+41 5.436E+28 3.624E+27 4.062E+35 6.318E+34 2.531E+24
7.350E+22 1737000 1.245E+29 2.976E+16 1.984E+15 2.223E+23 3.458E+22 1.385E+12
Inspired by Powering the Death Star with Twinkies by Scott Manley.