views:

187

answers:

4

The clock on the gym wall also shows the day name and the day of the month. This morning it showed Tuesday - 23.

The day obviously rotates through a cycle of 7 - and showed "Tuesday" correctly. The day of the month, though, presumably rotates through a cycle of 31 and showed "23" incorrectly - today is the 1st December (ie. not the 31st November). So this error has been slowly accruing over time.

Given the assumption that no-one has ever reset the clock, what's the most elegant, quick, optimised way of suggesting some of the possible dates for when this clock was bought brand new.

(Bonus credit for showing when the clock will again show the correct day/number combination.)

+1  A: 

01-Oct-17 is when the clock will again show the correct day/number combination.

PP
I could have done this by a program but decided to use a spreadsheet, with a 1-31 column on the left, an incrementing date column, and a test to see if the days matched.
PP
Going backwards the clock was last correct on 30 September 2008.
PP
In fact the clock was correct 1 July 2008 through 30 September 2008. Previous to that it was correct 1 December 2003 through 29 February 2004.
PP
A: 

Now = 1 Dec 2009.

1st day of the month minus 23rd of past month = 8 days (assuming 31 day month).

Moving back counting non-31-days month...

Nov, Sep, June, Apr, Feb (X3), Nov = 8 days offset

So it was bought before Nov 2008?

I didn't code a single line for it, so pardon me if the answer is way off.

o.k.w
A: 

The day of the week (i.e. Tuesday, ... etc) will always be correct, so it is irrelevant to your problem.

Assuming non leap year, you can build a table of 12 rows (1 per month) containing the number of days in this month minus 31.

  • Jan 0
  • Feb -3
  • Mar 0
  • Apr -1
  • May 0
  • Jun -1
  • Jul 0
  • Aug 0
  • Sep -1
  • Oct 0
  • Nov -1
  • Dec 0

You can build a table of the displayed date for every 1st of the month, by adding to the day of the previous month the related number in this list. If the number is negative or equal to zero, add 31 to the figure.

i.e. from the 1st Dec 09 (date at which the clock is displaying 23), you can go to the 1st Jan 10. You look at this table and find the figure next to Dec, it is 0. Add 0 to 23 and you know that on the 1st Jan 10, the clock will be displaying 23.

From the 1st Jan 09, you know that the date which will be displayed on the 1st Feb 10 is 23.

From the 1st Feb 10, you can compute the value for the 01 Mar 10, it is 23 + (-3) = 20.

... etc

So, now, at every start of month where you get a value of 1 in this table, you know that the dates in this month will be correct.


If you have to include leap year, you need a second table with the values for a leap year or make an exception for February.


If you want to use this computation for previous dates, substract the figure from the table and when the number you obtain is over 31, just substract 31 to get the day number.


Using these tables and taking in account leap years. The last past date at which the clock was correct was the 30 September 08 (it was correct between the 01-Jul-08 and the 30-Sep-08)

The next date at which it will be correct will be the: 01-Oct-17 and it will still be correct on the 30-Nov-17.

BlueTrin
Thanks for confirming my answers were correct.
PP
Yes you were correct on both counts, modded you up for providing the answers : )
BlueTrin
A: 

In Excel, you can test any date in A2 to see whether the clock will be correct on that date, with the formula =MOD(A2+19,31)+1=DAY(A2)

Stephen Denne
Ah yes, excel is indeed the most accurate tool for doing date algebra!#UTTER #FAIL http://www.grokdoc.net/index.php/EOOXML_Objections_Clearinghouse#The_Gregorian_Calendar
jsbueno