The Date Hack
The PrimeTime
Summary
This video breaks down the technical challenge of calculating the day of the week from a day count since the epoch. It explains how to move from simple modulo arithmetic to more efficient formulas, specifically exploring the logic behind handling negative numbers. The guide navigates through different algorithmic approaches, culminating in the fascinating use of bitwise operations and two's complement arithmetic, which allow computers to determine the day of the week with incredible speed and efficiency.
Chapters
- 0:00Introduction to computer science date problems
- 0:54Setting up the sponsor and context
- 1:48Deriving the basic day of the week formula
- 3:08Why the simple modulo 7 fails
- 3:23Correcting the formula for negative inputs
- 4:22The generalized formula for all numbers
- 4:52Henan's algorithm and optimization
- 6:27Nieri's algorithm introduction
- 7:11Explaining two's complement binary math
- 9:10The mathematical magic of bitwise operations
- 10:48Single instruction performance claims
- 10:58Closing thoughts and bits terminology
Topics covered
- The basic modulo 7 formula
- Adjusting for the epoch offset
+5 more topics (full content when you follow the channel)
Transcript excerpt
There are two hard problems when it comes to computer science. That's of course is naming things and getting a date. Now I know from great personal struggles the difficulty of of course getting a date and I thought I would help guide you through the process. You know, really teach those young budding computer scientists and vibe coders what exactly it takes to get a date and go on and live a happily married life. Now of course I'm talking about the fastest way to calculate the day of the week. Now this is one of the most amazing articles you have to see and we will first derive like the basic formula and then we'll see like a really cool just coincidental way to be able to make this work out and then the most insane bitwise operation that even thinking about it just gets me juiced. And I made a beautiful presentation for this. And you guys are always asking me for some technical video so…