Welcome to Project Lovelace! We're still super new so there are still tons of bugs to find and improvements to make. If you have any suggestions, complaints, or any comments at all please let us know on Discourse!

Speed of Light

You will learn about: submitting code and that light is fast.

Light is really fast: 299,792,458 meters per second to be exact. That's fast enough to make it almost 7.5 times around the Earth in one second! A spacecraft would take a few days to reach the Moon, but a beam of light could do it in 1.255 seconds.



We can calculate how long it takes a beam of light to reach places in space. Since light travels at a constant speed $c$, the time $t$ it takes to travel a distance $d$ is $t = d/c$. Try to submit some code with a function light_time(distance) that returns the time it takes light to travel that distance.


Input: A distance in meters (m).

Output: The time it takes for light to travel the input distance, in seconds (s).


Example 1

Input distance: 376291900 Output time: 1.255175

Example 2

Input distance: 299792458 Output time: 1.0


 Difficulty  Timesink
 Maximum runtime 60 s  Max. memory usage 250 MiB
 Function signature light_time(distance)

Write a function that accepts the input as function parameters and returns the correct output. Make sure to read the description above to produce the correct output in the correct format and use the correct function signature so we can run your code. A good first step is to try reproducing the example(s). Your code must not take longer than the maximum runtime to run and must not use more memory than the allowed limit.




You must be logged in to view your submissions.

Videos

Earth-Moon-Mars distances to scale, at LIGHT SPEED!, James O'Donoghue
Watch a beam of light travel to Mars and back to Earth in real-time.
Powers of Ten: A Film Dealing with the Relative Size of Things in the Universe and the Effect of Adding Another Zero (1977), Charles and Ray Eames
There are also interactive versions: The Scale of the Universe and Universcale. The original book is also online: Cosmic View: The Universe in 40 Jumps.

Notes

  • The speed of light is usually denoted by lowercase $c$, apparently for "constant" or from the Latin celeritas meaning quickness or swiftness.
  • Light takes 1.255 seconds to travel from the surface of the Earth to the surface of the Moon. The average distance between the Earth and Moon is 384,400 km but the radius of the Earth is 6,371 km and the radius of the Moon is 1,737 km, so in this case light actually travels 384,400 - 6,371, - 1,737 = 376,292 km.
  • The first measurement of the speed of light was made in 1676 by Ole Rømer but scientists argued about whether the speed of light was finite or infinite for a long time.

Let us know what you think about this problem! Was it too hard? Difficult to understand? Also feel free to discuss the problem, ask questions, and post cool stuff on Discourse. You should be able see a discussion thread below. Feel free to post your solutions but if you do please organize and document your code well so others can learn from it.