- Doomsday.py:
-
This program is an implementation of Conway's Doomsday algorithm that can find the day of the week of any given date.
-
I am trying to learn to do this in my head, so i figured writing it out like this would help.
-
I have added lots of comments and detailed variable names so it can be followed along with.
-
Here are the steps the program follows:
- Get century code by getting the remainder of the century (first 2 digits) / 4, the code its the number at that index in the list [2,0,5,3]
- Check if the year (last 2 digits) is evenly divisible by 4, if so its a leap year, only an issue if month is jan or feb
- Get the ammount of times 12 goes into the year
- Get the remainder of that
- Get the ammount of times 4 fours into that remainder
- Add the century code, twelves, remainder and fours
- Get the remainder of the sum / 7, that is the doomsday week day (0 is sunday, 6 is saturday) of the year
- Get the doomsday of the target month
- Find the distance from the day to the doomsday, (add one to the doomsday if jan or feb and a leap year)
- Divide the distance by 7, the remainder is the day of the week
-
Example:
22/11/1948
- 19%4 = 3, century code = 3
- 48/4 = 0, leap year
- 12/48 = 4
- 0
- 0
- 3 + 4 + 0 + 0 = 7
- 7%7 = 0
- 7
- 22-7 = 15
- 15%7 = 1
-
slalomsquid/Mini-Projects
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|