Question: Purpose: To practice recursion with a simple example.Moosetopias most famous rocket scientist, Zeno, has invented a new kind of space ship which will enableinterstellar travel
Purpose: To practice recursion with a simple example.Moosetopias most famous rocket scientist, Zeno, has invented a new kind of space ship which will enableinterstellar travel across the large distances of space very quickly. The technology is very complicated, andinvolves a lot of tedious messing about in hyperspace, but the actual motion of the ship is quite simple: If the distance to the destination is greater than meter, the ship will "fold space" and "jump" to aposition half way to the destination. It takes exactly one minute for the ships computer to do thecalculations prior to the jump. The jump itself is instantaneous. Any distance of meter or less will take exactly one minute, using normal impulse rockets.For example, if the ship has to travel meters, it will jump meters after the first minute, meters thesecond minute, meters the rd minute, and meters the fourth minute. Finally, the remaining meters takes one more minute. Thus the total time to travel meters is minutes. That seemsvery slow, and it is for small distances; the true value of this method only reveals itself for large distances.Write a recursive function called spaceTime that calculates the time needed for Zenos ship to travel agiven distance. In the same file, write a program that asks the user for a distance in meters console inputthen call your spaceTime function to calculate the time required to travel the given distance.Test your function out on all of the following examples: Average distance to the nearest coffee shop: meters about a typical Moosetopia city block Average distance from Moosetopia to its biggest moon: e meters about thousand km Average distance between our earth and our sun: e meters about million km Approximate distance between the sun and the closest star: e meters about lightyears Size of the observable universe: e meters about GigalightyearsSample RunYour program output might look something like the following: Zeno s drive requires : minutes to travel meters to Zeno s nearest coffee shop minutes to travel meters from Moosetopia to its biggest moon minutes to travel meters from our earth to our sun minutes to travel e meters from our sun to the nearest star minutes to travel e meters across the observable universe
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
