|
Recently I was trying to come up with a solution that can show person's age as "X years Y months and Z days".
Seems like a simple problem but then I realized there is more to it than it seems.
You can easily find out total years but when it comes to month it gets tricky. For example if someone's birth date is 05/01/2000. Lets say today is 20/03/2000.
(Date Format is : DD/MM/YYYY)
Option 1 :
Consider 05/01/2000 to 05/02/2000 as 1 month
+
Consider 05/02/2000 to 05/03/2000 as 1 month
+
Consider 05/03/2000 to 20/03/2000 as number of days
Option 2:
Consider 05/01/2000 to 31/01/2000 as count for number of days
+
Consider 01/02/2000 to 01/03/2000 as 1 month ( full calender month )
+
Consider 01/03/2000 to 20/03/2000 as number of days.
Add number of days from 1 & 3 as total number of days.
Which is correct way to look at it?
P.S. : This is not a programming question. I want to know your opinion on which is more accurate.
Zen and the art of software maintenance : rm -rf *
Math is like love : a simple idea but it can get complicated.
modified 30-Dec-11 22:58pm.
|
|
|
|
|
You're forcing me to think, so this is a programming question.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I don't understand your date format; please use an ISO 8601-compliant format -- YYYY-MM-DD
virang_21 wrote: which is more accurate
There are "accurate" and "not accurate", there is no "more accurate".
But I prefer your latter calculation.
|
|
|
|
|
PIEBALDconsult wrote: there is no 'more accurate'
I would beg to differ; you just reminded me on a mind numbing hour long brainwashing from one of our machinist instructors during my apprenticeship about 22 years ago!
Picture the scene, ten 16 year olds forced to huddle round and listen to some old coffin dodger give us a talking to on the difference between accurate and precise. (it was related to the merits of tolerance whilst machining)
The instructor went on:
You are tasked at throwing darts at a dart board, with the bullseye being the where you must get them.
From 20feet away you maybe get 1 bull, 2 outer-ring, a smattering around the pointy end of each number a couple around the Triple band.
From 10feet away you maybe get 3 bulls, 4 outer-ring, a and more clustered around the pointy end of each number, none outwith the Triple band.
From 5 feet away you maybe get 8 bulls, 8 outer-ring, and all your remaining around the pointiest ends of each number.
from 2 feet away you maybe get them all within the bull or outerring.
Now the closer you are the 'more accurate' you are.
However, if regardless of where you stood, you always got every dart in the bullseye then 'that is precise' (said in an old mans eastern European accent while stabbing a bit of paper with a pen as if it was the last thing he was every going to do).
|
|
|
|
|
+5
Thanks, Dave, that's a wonderful story, almost a "parable:" all the more powerful because it's from "real life."
Happy New Year !
best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
Well I must respectfully disagree.
You remind me of something I read some time back (I know not where) about computer representations of numeric values, accuracy, and precision.
Given three common numeric datatypes -- integer, single, and double -- all three can accurately hold the value three, they all hold three with equal precision; but none can accurately hold the value one third, integer being least precise, and double being most precise.
From this I deduce that accuracy is a boolean -- you are either accurate or you are not; if you are not accurate then you can hope for increased precision.
|
|
|
|
|
No - there is always rounding involved. Do you round to days? minutes? seconds?
|
|
|
|
|
That's a matter of precision and I demand accuracy.
|
|
|
|
|
Heisenberg may be the boss of your world!
|
|
|
|
|
Well, Hindenburg is like a bright shining star in the night.
|
|
|
|
|
Hmmm,
It looks like an Algorithm[^] question to me...
Both of your algorithms look bugged, you never mentioned how you handle leap years[^].
Best Wishes,
-David Delaune
|
|
|
|
|
I had that in my mind too.. I actually coded solution for option 2 but than I though about number of days exceeding 31... At times I get result like 27 years 3 month and 40 days which one will argue as not accurate ...
Zen and the art of software maintenance : rm -rf *
Math is like love : a simple idea but it can get complicated.
|
|
|
|
|
Or leap seconds, or non-leap year century years, or international date line changes (qv Samoa), nor are you taking into consideration location changes (say from London to New York).
And which calendar?
What of Ethiopia and its 13 months of the year?
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Hmmm,
Well besides leap seconds and non-leap years, none of the above would apply to an ISO GMT date and time used by a typical engineer. Besides why are you responding to me as if I am the OP?
Best Wishes,
-David Delaune
|
|
|
|
|
I think you will find that engineers often have to take +/- GMT (UTC) into account when using time calculations, navigation systems, flight controls, communication devices, power consumptions etc.
As for responding as I did, natural stupidity plus I haven't risen from my bed yet!
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Dalek Dave wrote: I think you will find that engineers often have to take +/- GMT (UTC) into account when using time calculations, <layer>navigation systems, flight controls, communication devices, power consumptions etc.
Well, I and other engineers developing navigation systems typically use GMT (UTC) for everything and then convert it to a local time zone. Navigation and control systems are part of my portfolio[^]. If you see any naval vessels in any of DaveAuld's photographs... there is a strong possibility that I worked on the team developing the dynamic control system.
Best Wishes,
-David Delaune
|
|
|
|
|
I understand that UTC is the format, (Good portfolio btw!), but I was just making the point that times often need taking into account.
I read somewhere that the GPS satellites need the clocks resetting every 1/30th of a second owing to relativistic variance. Quite a task, being that accurate, 200 nanoseconds a day?
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Dalek Dave wrote: (Good portfolio btw!)
Thanks, I have since moved on to a much more exciting field of engineering/research.
Dalek Dave wrote: I read somewhere that the GPS satellites need the clocks resetting every 1/30th of a second owing to relativistic variance. Quite a task, being that accurate, 200 nanoseconds a day?
Well, I don't think the clocks reset periodically though. If I had to guess... I would say that they most likely had to reset once after launch... due to less gravity. I believe they contain a small amount of cesium or other radioactive material that decays at a fairly constant rate and use this to keep track of time. With GPS there are civilian, military (U.S. and Russian) and civilian/commercial GPS satellites... all with a varying degree of accuracy... we could usually estimate the vessels geodetic position to within about 3 meters accuracy depending on weather conditions.
Best Wishes,
-David Delaune
|
|
|
|
|
In a car, at 70 mph, 3 metres is good enough.
Having a guided missile travelling at 2000mph, 3 metre accuracy may prove somewhat more of a problem.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Dalek Dave wrote: In a car, at 70 mph, 3 metres is good enough.
I guess I should have qualified my statement. Using GPS the resolution was around an average of 3 meters. However most vessels under navigational control will have multiple position reference sensors, perhaps including a CyScan laser sensor which would give an extremely high accuracy over short distances. There are many other types... radascan (radio wavelength) ect... all with strengths and weaknesses.
Dalek Dave wrote: Having a guided missile travelling at 2000mph, 3 metre accuracy may prove somewhat more of a problem.
Heh, they are typically using lasers. Interesting how you observed these technologies being related.
Best Wishes,
-David Delaune
|
|
|
|
|
"Once the rockets go up who cares where they come down?" -- Tom Lehrer
|
|
|
|
|
Randor wrote: Well, I don't think the clocks reset periodically though. If I had to guess... I would say that they most likely had to reset once after launch... due to less gravity.
The reason for the reset is because of the speed of the satellites are traveling. And The theory of relativity.
Just My 2 cents.
Frazzle the name say's it all
|
|
|
|
|
Hi Frazzle,
Yes, you are of course correct that the speed will also have an effect on GPS clocks relative to ground clocks. However as an object move away from the center of the Earth... it is moving into a lower curvature of space and will be subject to time dilation[^].
Best Wishes,
-David Delaune
[Updated]
Changed/Clarified my statement to include time dilation rather than relativistic mass.
modified 2-Jan-12 2:08am.
|
|
|
|
|
This is me getting super nerdy...
The mass of the object does not change as it moves away from the earth --> Wikity Clickety[^]:
An object's weight depends on its environment, while its mass does not: an object with a mass of 50 kilograms weighs 491 Newtons on the surface of the Earth; on the surface of the Moon, the same object still has a mass of 50 kilograms but weighs only 81.5 Newtons.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Hi Guy,
Sounds like you are referring to invariant mass[^]. I am more or less referring to relativistic mass[^].
As you probably already know... if mass always stayed the same and never changed... we could easily accelerate to the speed of light... and actually beyond that limit... it is the increase of mass that prevents us from doing that.
If you drove in your car today... as you were driving around... you gained a small amount of mass while moving relative to your surrounding objects at rest.
Also... if you saved any files onto your hard drive today... the hard drive became slightly more massive.
If you take a rubber band... and stretch it with your fingers... the potential energy caused that rubber band to get slightly more massive.
Best Wishes,
-David Delaune
|
|
|
|