25
Using the following table (source) write some code that takes the names of two planets and returns the distance between them:
+-------------------+---------------+
| Planets | Distance (km) |
+-------------------+---------------+
| Mercury -> Venus | 50290000 |
| Venus -> Earth | 41400000 |
| Earth -> Mars | 78340000 |
| Mars -> Jupiter | 550390000 |
| Jupiter -> Saturn | 646270000 |
| Saturn -> Uranus | 1448950000 |
| Uranus -> Neptune | 1627450000 |
| Neptune -> Pluto | 1405380000 |
+-------------------+---------------+
Examples, input then output:
Mercury, Mars
170030000
Neptune, Jupiter
-3722670000
Earth, Earth
0
Note the negative sign there, as Jupiter comes before Neptune. They are also all integers.
Pluto doesn't have to be included (mostly because of a weird orbit which makes it hard to work out the distance - that distance given is my own calculation, but as Pluto is all famous now...).
By distances between planets I'm meaning orbits - I don't expect a date and working out where they are.
This is code golf, shortest code wins.
10+1 for not "coz Pluto ain't a planet" – Optimizer – 2015-07-15T16:04:19.190
@Optimizer I'm doing a project which needs the distances and nobody can agree! I resorted to using it's orbital period and orbital speed... – Tim – 2015-07-15T16:04:58.230
Can our function/program return a float? i.e.
Mercury, Mars -> 170030000.0
? – Kade – 2015-07-15T16:06:24.413@Vioz- I'm gonna say no, they're all integer distances. – Tim – 2015-07-15T16:06:51.890
8It's implied, but are we assuming the holy moment in time where the planets are all in a straight line and the distance between any two non-adjacent planets is the sum of distances in between? – Sp3000 – 2015-07-15T16:10:02.080
@Sp3000 yes. will clarify – Tim – 2015-07-15T16:10:30.513
3Is there a penalty for including Pluto (besides the bytes)? I feel kinda bad for it, it just had it's big day and all... – DeadChex – 2015-07-15T16:23:26.613
@DeadChex no penalty :) I'll add it onto the table – Tim – 2015-07-15T16:26:15.533
@Sp3000 It doesn't have to be a holy moment as the distances are pairwise. – Optimizer – 2015-07-15T16:39:57.473
I'm testing something right now, since Python will attach an L to a value that's too large, is it OK if I return something like
-3722670000L
? – Kade – 2015-07-15T17:31:05.497@Vioz- yeah that's fine. – Tim – 2015-07-15T18:00:08.467
do you care about the orbits' eccentricity? or assume circular orbits? edit nvm i read the link to the data source – Plato – 2015-07-15T20:14:58.593
@Plato use the distances provided. They're circular orbits here. – Tim – 2015-07-15T20:15:27.723
Is the input guaranteed to be a valid planet? – kirbyfan64sos – 2015-07-17T17:03:04.303
@kirbyfan64sos yes – Tim – 2015-07-17T21:37:20.673