Mental juggling: Calculating the day of week - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: Mental juggling: Calculating the day of week (/thread-152732.html) |
Mental juggling: Calculating the day of week - Thomas Klemm - 07-06-2009 My father has a quirk: When he meets someone new, he asks after the date of birth and
Let me explain it first with an example: 22.06.1955 Day 22 -> 1
Day
This one is easy: it's calculating the remainder after division by 7. Example: 22 = 3 * 7 + 1Actually you don't have to divide by 7. You just need to know the closest multiple of 7 which is smaller or equal and then calculate the difference: 22 - 21 = 1
Month
Here you don't have to calculate anything but keep a table in your mind: Month 1 2 3 4 5 6 7 8 9 10 11 12As I can't remember such a table very well I rearranged it a little: Month Magic numberFor Januray and March the mapping is identity, for October it is 0 which means it can be ignored. Then you can see that the 2nd and 3rd line both start with 6. In the 2nd line 1 4 from the first line is repeated but shifted by 1 whereas in the 3rd line 1 is added giving 2 5. Well, the last line: 10 is 0 and 1 added to 2 gives 3 and 5 is keept. But I'm sure you'll find a different way to memorize this table.
How did I calculate this mapping? month # days sum % 7(*) Since February is the last month in the list we don't have to take leap years into account here. This is the reason why we started with March.
Year
Leap years make things complicated. Here again we have a mapping table: 0 : 00 06 17 23 28 34 45 51 56 62 73 79 84 90 101 107Search the year (- 1900) in the table and find the corresponding number in the leftmost column. Now this is something I don't want to learn by heart. However you may notice that the pattern repeates after 28 years so we just need to remember the first 28 years. Unfortunately calculating modulo 28 isn't something I can do easily in my mind.
This is the easiest way I came up to calculate the number:
Example: 55 = 52 + 3As the calculations are carried out modulo 7 we can also subtract the difference to the closest multiple of 7 smaller than that number in steps 3 and 4. Example: 46 = 44 + 2Shortcut for years that are a multiple of 7:
Example: 49 = 48 + 1Important note: You may have noticed that the mapping table for the months starts with March. Thus January and February belong to the year before the actual year. Therefore for these two months the year has to be reduced by 1 before any calculations.
There are different ways to do that calculation. But it turned out that I can calculate
Quote:
Day of the week
The following table is used to map the resulting number to the day of the week: 0 Sunday
Explanation
What we actually do is calculating the difference of the date to 28.02.1900 modulo 7. 22.06.1955Since 28.02.1900 was a Wednesday the mapping table of the months starts with 3.
What remains unexplained are the two formulas to calculate the mapping of the year: Let's assume y = 4n + r ; 0 <= r < 4
Last not least the case where the year is a multiple of 7: y = 4n + r = 7k = 0 (7)
Restriction
The method described here works only for dates from 01.03.1900 to 28.02.2100.
Examples6 July 1979
79 - 76 = 3 or shortened
79 76 3
December 7th, 1941
41 - 40 = 1 or shortened
41 40 1
20.02.1964
63 - 60 = 3 or shortened
63 60 3
Programming
How about a training program for your favorite HP calculator that displays a random date Edited: 7 July 2009, 1:40 p.m. after one or more responses were posted
Re: Mental juggling: Calculting the day of week - Allen - 07-06-2009 This is a great write up.. I recommend making an article of the same title and also posting there. :)
Re: Mental juggling: Calculting the day of week - Mad Dog ebaycalcnut - 07-06-2009 Pretty cool trick.
Do people get suspicious of identity theft when asking their birthdate?
Re: Mental juggling: Calculting the day of week - PeterP - 07-06-2009 Awesome post Thomas, please make it an article! Cheers
Peter
Re: Mental juggling: Calculting the day of week - Thomas Klemm - 07-07-2009 cf. 926: Mental juggling: Calculating the day of week
Re: Mental juggling: Calculting the day of week - Thomas Klemm - 07-07-2009 Your question is interesting since people are indeed sometimes irritated. But usually they just tell their date of birth. However someone turned the table on him and told him only birthday and weekday and asked him to tell the year. He had a little longer and guessed the person too young but the result would have been possible. I remember a similar irritation when traveling in Viet Nam since people always ask you how old you are. Yet they need to know because they call you different depending on whether you are older or younger than they are.
So I assume that identity theft isn't the main concern but simply the fact that somebody asks something personal.
Re: Mental juggling: Calculting the day of week - Juergen Keller - 07-07-2009 Great article, thank you! This remembers me of the R500/7T relay computer which a colleague of mine has built. He usually demonstrates the computer by running the 'day of the week' program. The program runs for about 20 seconds!
Juergen
Re: Mental juggling: Calculating the day of week - Bernard Rochlin - 07-09-2009 See the formula by John Horton Conway called the 'Doomsday Rule' http://en.wikipedia.org/wiki/Doomsday_algorithm Edited: 9 July 2009, 7:45 a.m.
Re: Mental juggling: Calculating the day of week - Thomas Klemm - 07-09-2009 Quote:
This is Lewis Carroll's method already mentioned. So you can also combine my method (for the year) with Doomsday Algorithm if you like. Then you don't have to memorize the mapping table for the months.
|