Live data from Hacker News

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

rudy.ca

51–60 of 68 posts

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

#51
post #50

Earlier quoted context omitted.

But why do you call them Pi-Days? Pi Day is 3/14 because that's somewhat similar to 3.14, which is Pi to 3 significant digits..

They are the same weekday as 3/14 and it makes a little more sense than 'Doomsday', which the article chooses.

I vehemently disagree, you can't just redefine Pi-Day to what you want. Pi Day is 3/14, not 4/4 or 6/6.

As for calling it Doomsday, well, it's from the title of the paper about the algorithm, by the man who invented it, the famous John Conway: https://en.wikipedia.org/wiki/Doomsday_rule

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

#52
Here's a summary of the methods I know for computing the factor based on the last two digits of the year that gets added to the factor from the century number to get the Doomsday for the year.

Notation: "A // B" is integer vision (think Python 3 // operator). "A, B = C /% D" means that "A = C//D" and "B = C % D". "A ≡ B" means A and B are the same mod 7. "A ≡⁴ B" means A and B are the same mod 4. I'll use x for multiplication. X + means the four values A+a, X+b, X+c, X+d.

Let Y be the last two digits of the year.

Observation: 365 ≡ 1. If it weren't for leap years, the year factor would simply go up by 1 each year. A leap year pushes the start of the next year back a day, and that's cumulative, so we need a correction of the number of leap years that have past.

1. That gives the first, and simplest, way to compute the year factor for year Y.

  return Y + Y//4
Advantage: simplest algorithm.

Disadvantage: numbers get larger than you might be comfortable with for fast mental meth. Doing 99, for example, gives 99 + 99/4 = 99 + 24 = 123 ≡ 4, which has plenty of opportunity along the way to goof.

Many people will do better with a method that uses a little more complicated algorithm but cuts down the size of the numbers.

2. The divide by 12 method, which is the one given in the article, does this.

  a, b = Y /% 12
  c = b // 4
  return a + b + c
Here's why it works.

  Y = 12 a + b
  Y//4 = 3 a + b//4
       = 3 a + c
  Y + Y//4 = 15 a + b + c
           ≡ a + b + c
Advantage: a Disadvantage: Still easy for many people to goof on the initial /%.

Note: if you divide by 20 instead of 12, you get a similar method, except that you'll need to use 4a instead of a. Since a is at most 4, 4a is not large. For many people %/ 20 might be sufficiently easier to deal with in mental math than %/ 12 that it is worth the cost of having to multiply by 4.

3. The odd 11 method.

  Y += 11 if Y is odd
  Y //= 2
  Y += 11 if Y is odd
  return -Y
The easiest way to see that this works is to go back to Y + Y//4. Write Y = 4q + r, where r = 0, 1, 2, or 3.

The first conditional add 11 step turns 4q + into 4q + . Dividing by 2 then gives 2q + . The second conditional add 11 gives 2q + . Negating mod 7 gives 5q + , which is 4q + + q = Y + Y//4.

Similar considerations give other divide by 2 and negate methods. If you note that if Y = 4q, then Y + Y//4 ≡ -(Y//2), then it is just a matter of how to take into account the r in 4q + r when r != 0. One way to do that would be first subtract r, then do the -(Y//2), and then add r back. That works because none of the r != 0 years are leap years, and so we just need to add 1 for each of them.

Another way would be to just go ahead and do -(Y//2), and then add in a correction based on r. Let Y = 4q + . Then -(Y//2) ≡ 5q + . We want 5q + , so we have to add 0, 1, 3, or 4 if r = 0, 1, 2, 3, respectively.

That last correction can be split into two parts: add 1 if Y is odd, plus add 2 if Y//2 is odd. That gives:

  t = Y odd ? 1 : 0
  Y //= 2
  t += 3 if Y is odd
  return -Y + t
4. The method I actually use, which views the two digit year as a decade part and a year within the decade part, and operates on them separately. Since I gave a long description of it yesterday, I'll just link to that [1] here.

[1] https://news.ycombinator.com/item?id=21926543

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

#53

If not for religious groups, we could have had World Calendar and all this would be unnecessary: https://en.m.wikipedia.org/wiki/World_Calendar .

Starting the week on a Sunday seems to be a very american centric view for a ‘World’ Calendar. I get that it has to start on _a_ day but don’t see how a consensus could be reached here.

Not to mention that the ISO says Monday is day 1 of the week:

https://en.wikipedia.org/wiki/ISO_8601

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

#54

If not for religious groups, we could have had World Calendar and all this would be unnecessary: https://en.m.wikipedia.org/wiki/World_Calendar .

We not just have 13 months of 28 days each? This would make the days of the week always cycle synchronously with the days of the month. Then you have one day left over for New Years and that extra Leap Day every 4 years that your linked calendar proposes. If you are going to redo something like a calendar, ending up still having different length months and weeks that drift against them seems like a non-victory.

The primary reason is that 13 is prime. 12 is a better number in this case for a few reasons.

12 is what we already have. So nothing would have to change in that regard. We could keep the names as they are, despite the fact they are out of order as it is.

I used to think the same way, but after seeing this calendar, it would be easier to integrate this into what we currently have, just the amount of days have changed.

And, this calendar would work well with businesses. Most businesses are based on quarters. Not that it is significantly more difficult to track 13 weeks (they would be static after all), the pushback would be less, arguably.

And the world calendar is cyclical, just on a quarterly scale, rather than a monthly scale. I'd argue the monthly cycle makes more sense. But the math of the Earth's rotation doesn't make for a nice calendar.

I feel the world calendar would be easier to integrate, and a little nicer (I am a huge advocate for base 12 anyway, that's always been a big hangup for me for the international fixed calendar).

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

#56
post #53

Earlier quoted context omitted.

Starting the week on a Sunday seems to be a very american centric view for a ‘World’ Calendar. I get that it has to start on _a_ day but don’t see how a consensus could be reached here.

Not to mention that the ISO says Monday is day 1 of the week: https://en.wikipedia.org/wiki/ISO_8601

But what is day 0? :)

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

#57

If not for religious groups, we could have had World Calendar and all this would be unnecessary: https://en.m.wikipedia.org/wiki/World_Calendar .

If not for people, we could have had a World Calendar? A majority of the earth’s population are religious, so you can pretty easily substitute people for religious groups.

The point is that specific religious groups opposed it because it would break the seven day cycle of worship, leaving room for the Devil (insert evil laugh here). Reasonable people pointed out that it would leave people with the choice to worship on an extra holiday, but religion and personal choice don’t get along so in the end religious zealots won out.

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

#58

Earlier quoted context omitted.

Why does the week start on a Sunday in that calendar?

In some countries Sunday is considered the first day of the week, which is quite strange for me, as here it's Monday. Do Americans, for example, feel like "a new week has started" on Sunday morning? For me Saturday and Sunday feel as one block, it's weird to imagine a separation in there. But perhaps someone who grows up with that calendar feels like Saturday is end-of-the-week winding down, and Sunday is a start-of-…

American and even I've never understood why Sunday is considered the first day on some calendars. It has always, in my experience, been considered a weekend day and you would think that the "weekend" is at the end of the week, and Monday has long been the default start of a work or school week.

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

#59

My Autistic son does this in a couple of seconds. He can only really do the last 50 years tho. Savants who do this are called "human calendars".

What method does he use to calculate?

He can't explain it. AFAIK none of the Human Calendars can, there have been studies.

I reckon it's memory related, he has an incredible memory and can tell you everything he did on a specific day in the past!

Maybe at some point he just scanned the Windows calendar or something!? We (and his teachers) can't work it out.

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

#60
post #50

Earlier quoted context omitted.

They are the same weekday as 3/14 and it makes a little more sense than 'Doomsday', which the article chooses.

I vehemently disagree, you can't just redefine Pi-Day to what you want. Pi Day is 3/14, not 4/4 or 6/6. As for calling it Doomsday, well, it's from the title of the paper about the algorithm, by the man who invented it, the famous John Conway: https://en.wikipedia.org/wiki/Doomsday_rule

I didn't come up with this. According to the article, Roman Weil of Princeton teaches the same.
Post reply on HN