Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hello Everyone,
I have a question that maybe an experienced programmer can help me with.
Example: If a train left NY at 4:00PM and Arrived in Chicago at 11PM How long was the trip.
(Easy part) But here the clincher: and how many hours and minutes were at night and how many hours and minutes were during the day. You will need to take into consideration the time zones it crosses and the official sunset and sunrise for each city.
He is the gist of what I am trying to accomplish. I have a asp.net function that can tell me what time-zone each city is in and when the sun rise and sets for that day for each city. Now what I am trying to accomplish is this. I am trying to develop a function that will tell me how much time I was on the train during the day hours and minutes and then how much time I was on the train at night. Anyone have any ideas??? Has anyone heard of any function or javascript out there that would accomplish this???
Thanks In advance.
Posted
Comments
Sergey Alexandrovich Kryukov 1-Jan-11 20:38pm    
Looks like a deeply artificial and boring exercise. Why? Is it a home assignment? Perhaps assigned by some teacher who is out of good ideas? Just asking...

1 solution

Oh, great.
This is not about programming but about elementary mathematics (well, very elementary).

This problem is ill-posed. You cannot calculate this time, because the route and schedule is not provided. In other words, you need a detailed trajectory of the train in the space-time (called World line) and information about sunset/sunrise for every point in space (not just for each city). Also, this, strictly speaking, depends on how you define sunset/sunrise: it can be a local time in trajectory point or official value for the time zone, which is slightly different. Also, you should take into account, that sunset/sunrise changes as the train goes.

I can explain why you cannot solve this problem without this additional information.

To illustrate this, let's consider two different schedules. Consider the train move in a straight line. In one case, train moves exactly half of the way at very slow speed, the rest of the way at fast speed. In second case is just the opposite: fast, then slow, to take the same time for the whole travel. As the train moves East to West and departs before sunset, it meets sunset at some point which happens sooner for second case. Draw three World lines on a 2D picture (abscissa: time, ordinate: longitude, two lines for two train schedules and third line for sunset points), show intersections of the train lines with the sunset line and you will see it.

Please don't tell me now it is that the train moves at constant speed along straight trajectory or other assumptions. 1) In real life this is not the case; 2) even if you want to solve very idealized problem, none of the idealization are assumed, but should be specified precisely.

The problem is finalized: there is no unambiguous solution.
 
Share this answer
 
v2
Comments
Robert Adamo 3-Jan-11 19:15pm    
Well thanks for the great insight but, I must disagree with your findings. Greater details is needed I agree. But the exercise is not futile. The mathematics is a given. But the programing is where the problem is. I already have developed a function that is 99% accurate, my problem is that the the variable between sunrise, sunset and the datetime overlap causing the two function to clash. But thanks anyway... If anyone else would like to comment and or have heard of some javascript that can accomplish this task I would be grateful.
Sergey Alexandrovich Kryukov 3-Jan-11 19:55pm    
You can disagree in only one way: find a mistake in my reasoning and proof it's wrong. To do this you should show unambiguous solution. You can also say mathematical model should be more simple, but you did not describe it in first place. You could have said something like: motion in a straight line, constant speed. How can you say your function is 99% accurate, if by increasing the speed difference one can make it incorrect to any preset degree? By the way, 99% accurate means incorrect, period.

Well, it would be interesting to hear about your ideas and reasoning on the matter, but not just declarations.

Thank you and good luck.
Espen Harlinn 28-Feb-11 15:53pm    
Good points - going a long way towards stating the requirements for a solution, my 5
Sergey Alexandrovich Kryukov 1-Mar-11 4:01am    
Thank you. It was kind of difficult discussion.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900