Live data from Hacker News

Calculate the day of the week for any date in your head

rudy.ca

1–10 of 68 posts

Re: Calculate the day of the week for any date in your head

#3
For all but the most basic details my rule is that if I have to remember it, the system is broken. I know a small handful of passwords off the top of my head, a few email addresses, my wife's and my phone numbers, and the phone number of my home during childhood. (I'm obviously exaggerating, you know, for dramatic effect.) This trick requires so many mnemonic devices that it makes my head spin. It's still impressive if you can do it. Just not for me.

Re: Calculate the day of the week for any date in your head

#4
This looks like an algorithm that could be useful if programmed rather than carried around in one's head.

It also still requires a lookup to bootstrap it: the day-of-week of the last day of February for the selected year. So it's a clever and well-observed compilation of identified patterns, but not self-contained.

Re: Calculate the day of the week for any date in your head

#5

This looks like an algorithm that could be useful if programmed rather than carried around in one's head. It also still requires a lookup to bootstrap it: the day-of-week of the last day of February for the selected year. So it's a clever and well-observed compilation of identified patterns, but not self-contained.

Did you read the whole thing?

Re: Calculate the day of the week for any date in your head

#6

This looks like an algorithm that could be useful if programmed rather than carried around in one's head. It also still requires a lookup to bootstrap it: the day-of-week of the last day of February for the selected year. So it's a clever and well-observed compilation of identified patterns, but not self-contained.

The version they have here is somewhat inefficient and not well presented.

You can get from the year to the doomsday by a simpler formula:

If odd, add 11; divide by 2; if odd, add 11. Count up to nearest multiple of 7

So e.g. 1955 turns into 66 turns into 33 turns into 44 turns into 5. Add that to 4 for the century (1900 is 4, 2000 is 3, that's all you really need to memorize) and you get 9, so the doomsday for 1955 is Monday.

From there it's simple, 4/4 6/6 8/8 10/10 12/12, 9/5 7/11 per the mnemonic mentioned, last day of February, Jan 3/4 depending on leap year, and March 7 counting forward from February.

There, that's the entire algorithm.

Re: Calculate the day of the week for any date in your head

#7

For all but the most basic details my rule is that if I have to remember it, the system is broken. I know a small handful of passwords off the top of my head, a few email addresses, my wife's and my phone numbers, and the phone number of my home during childhood. (I'm obviously exaggerating, you know, for dramatic effect.) This trick requires so many mnemonic devices that it makes my head spin. It's still impressive…

You only need to remember 5 things:

- For 2020, the doomsday is Saturday.

All the dates below are doomsdays (So this year they are all Saturdays):

- 4/4, 6/6, 8/8, 10/10, 12/12, easy enough

- 9/5, 5/9, 7/11, 11/7 (9-to-5 at 7-11)

- 0th of March (last day of February)

- 3rd of January for non-leap years, and 4th of January for leap years. So this year the 4th is Saturday.

And to calculate dates: mod 7.

So e.g. 7th of July: it's is 4 days before Saturday 7/11, so it's a Tuesday.

Re: Calculate the day of the week for any date in your head

#8
post #6

This looks like an algorithm that could be useful if programmed rather than carried around in one's head. It also still requires a lookup to bootstrap it: the day-of-week of the last day of February for the selected year. So it's a clever and well-observed compilation of identified patterns, but not self-contained.

The version they have here is somewhat inefficient and not well presented. You can get from the year to the doomsday by a simpler formula: If odd, add 11; divide by 2; if odd, add 11. Count up to nearest multiple of 7 So e.g. 1955 turns into 66 turns into 33 turns into 44 turns into 5. Add that to 4 for the century (1900 is 4, 2000 is 3, that's all you really need to memorize) and you get 9, so the doomsday for 1955…

To go from "any" century, you can also memorize "2053", which is the days in a 4-year cycle: 2000 = 2 = tuesday; 2100 = 0 = sunday; 2200 = 5 = friday; 2300 = 3 = wednesday.

For years other than the centuries, we need to add an offset. Given the year CCXX, we have:

    (a, b) = divmod(XX, 12)
    c = b // 4
    offset = a + b + c
    doomsday = start + offset
E.g., for 2020 (XX == 20) we get:

    start = 2  # from the "2053" rule
    (a, b) = divmod(20, 12)  # (1, 8)
    c = b // 4  # 2
    offset = 1 + 8 + 2 = 4 (mod 7)
    doomsday = start + offset  # 2 + 4 = 6 = saturday

Re: Calculate the day of the week for any date in your head

#9

For all but the most basic details my rule is that if I have to remember it, the system is broken. I know a small handful of passwords off the top of my head, a few email addresses, my wife's and my phone numbers, and the phone number of my home during childhood. (I'm obviously exaggerating, you know, for dramatic effect.) This trick requires so many mnemonic devices that it makes my head spin. It's still impressive…

So do I.

Except my wife number, which I should learn. But I know how to say if a month is 30 or 31 days by counting my knuckles.

These are the kind of "hardly important but easy to remember tricks" I like

Re: Calculate the day of the week for any date in your head

#10

This looks like an algorithm that could be useful if programmed rather than carried around in one's head. It also still requires a lookup to bootstrap it: the day-of-week of the last day of February for the selected year. So it's a clever and well-observed compilation of identified patterns, but not self-contained.

> This looks like an algorithm that could be useful if programmed rather than carried around in one's head.

It is. I remember this being one of my programming assignments in college. Another one is determining whether a year is a leap year.

Post reply on HN