DEV Community

Cover image for Doomsday Algorithm
Mohamed Elsobky
Mohamed Elsobky

Posted on

Doomsday Algorithm

The Doomsday rule, Doomsday algorithm or Doomsday method is an algorithm of determination of the day of the week for a given date.

The algorithm is simple enough that it can be computed mentally, some people could usually give the correct answer in under two seconds

How The Doomsday Algorithm work ?

Doomsday Algorithm takes advantage of each year having a certain day of the week upon which certain easy-to-remember dates, called the doomsdays

for example, the last day of February, 4/4, 6/6, 8/8, 10/10, and 12/12 all occur on the same day of the week in any year, we can use that to determine what day of the week for any date in the year if we know what day is the doomsdays for our year

After you have determined which day will be the doomsdays for the year you want to know, you can simply find out any day of the week for any date in the year by counting forward/backward from the nearest doomsday to the date you want to know

The question here is how can we determine what day the doomsdays will be for the year we want to know?

The Rules of Doomsday Algorithm

I created an application based on this algorithm to determine the day of the week with an explanation of the algorithm directly on the date you entered. You can view it from here : https://doomsday-algorithm.vercel.app/

Let’s take a random date and explain the algorithm to it for example 7/9/1812

  1. Start by taking the last two digits of the year, this is your startingNumber in our case it will be (12)
  2. Divide the startingNumber (12) by four and ignore the remainder : 12 / 4 = 3
  3. Add the last result (3) to the startingNumber : 3 + 12 = 15
  4. Find the remainder of last result (15) divided by 7 : 15 % 7= 1 ,(Or find the nearest number less than 15 and divisible by 7 and substravted from 15)

Now we want to find what is the century’s anchor day , we can simply know that from that table here

The table in repeat you can easily know the doomsday for any century

Doomsday Century

  • After we determined the century’s anchor day Friday we will add the last result to that day Friday+ (1) = Saturday

Now we know the doomsday for a date year 1812 is Saturday we need to Find the closest doomsday and we can do that according to this table

Doomsday Month

(Note if the year is a leap year the doomsday for January will be 4 and February will be 29 and if is not a leap year January will be 3 and February will be 28)

we know now 5 September is Saturday now we can simply count from 5/9 to 7/9 the result will be Monday

( Note: If the difference between the two dates is large, you can subtract or add 7 until you reach the nearest number to the specified date, and then you can count )

Resources
Doomsday rule

Top comments (0)