Code Wars V
     

Program / Task Name:

   The Cosmic Milkman

Level:

 

 Advanced

Point Value:

 

 16

 

Task Description

Long, long ago, in a galaxy far, far away…

A milkman sets forth in his starship to makes his rounds to all the planets in his solar system.

His solar system was unique such that all the habitable planets orbited in the same plane, giving the solar system a 2-Dimensional look.  His solar system was also very unique in that all the habitable planets moved through space at the same uniform speed of 50,000Km per hour, either clockwise or counter-clockwise around the sun (or vice versa if you’re looking at the solar system from the opposite direction), with the only difference being their distance from the sun and their locations in the arc of their orbits.  

At an arbitrary time 0, all the planets are located as follows: distance from the sun (the center of the system); degrees into the arc of orbit around sun relative to an arbitrary positive x-axis (see picture below) counting in a counter-clockwise direction; and the direction of orbit:

Planet X – 1,000,000Km; 90 degrees; moving clockwise

Planet Y – 5,000,000Km; 50 degrees; moving clockwise

Planet Z – 10,000,000Km; 290 degrees; moving counter-clockwise

Planet A – 20,000,000Km; 230 degrees; moving counter clockwise

Planet B – 50,000,000Km; 140 degrees; moving clockwise

PlanetsPlanet C – 120,000,000Km; 275 degrees; moving counter-clockwise

 

Here is a rough sketch of the solar system at time zero (distances not to scale):

 

Other things to consider:  our traveling salesman’s spaceship can only fly at a maximum speed of 60,000Km per hour and assume that it takes him practically no time to drop off his shipment of milk once he arrives at a planet.  Consider the constant pi = 3.141592654.  Assume locations given for each planet are for a point at the center of each planet and ignore the diameter of the sun and the planets when calculating distances.  Math Hint: the x and y coordinates of a planet are can be determined using rcosΘ and rsinΘ respectively.

Your job is to write a program that calculates the minimum total length of time it takes the milkman to travel a given route.  Be careful to be exact.  A correct answer must be within one hour of the judges’ calculated time.

Program Input

The input for the problem will be provided as arguments on the command line when the program is executed as follows:

prob15 2500 X A B Z C Y X
  • Arg1: is the time (in hours) relative to time 0 mentioned above that the salesman begins his trip from his home planet.  Do not count this time in the total trip time.
  • Args 2 – 8: are the list of planets, in the order that the milkman visits them, ending at his home planet.  There will be exactly seven “hops” to the milkman’s trip in order to visit all the other planets and return home.  The home planet may vary from the example below.

Program Output

Print out the minimum time in hours that the trip will take as shown below:

The minimum numbers of hours for the trip is: 6121

Although the judging input will vary from this example’s input, this example can be used for verifying your program prior to submitting to the judges.  Here are some more details for this example:

Leg Time(mins): 20909 From X To A
Leg Time(mins): 45743 From A To B
Leg Time(mins): 47260 From B To Z
Leg Time(mins): 124597 From Z To C
Leg Time(mins): 124752 From C To Y
Leg Time(mins): 4016 From Y To X
Total Time(mins): 367277
Total Time(hrs): 6121

 

hp Code Wars
Hello -- Dominos?...
   
  (c) 2004 Hewlett-Packard Company