How to resolve the algorithm Doomsday rule step by step in the 11l programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Doomsday rule step by step in the 11l programming language

Table of Contents

Problem Statement

John Conway (1937-2020), was a mathematician who also invented several mathematically oriented computer pastimes, such as the famous Game of Life cellular automaton program. Dr. Conway invented a simple algorithm for finding the day of the week, given any date. The algorithm was based on calculating the distance of a given date from certain "anchor days" which follow a pattern for the day of the week upon which they fall. The formula is calculated assuming that Sunday is 0, Monday 1, and so forth with Saturday 7, and which, for 2021, is 0 (Sunday). To calculate the day of the week, we then count days from a close doomsday, with these as charted here by month, then add the doomsday for the year, then get the remainder after dividing by 7. This should give us the number corresponding to the day of the week for that date. Given the following dates:

Use Conway's Doomsday rule to calculate the day of the week for each date.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Doomsday rule step by step in the 11l programming language

Source code in the 11l programming language

F isleap(year)
   R year % 4 == 0 & (year % 100 != 0 | year % 400 == 0)

F weekday(year, month, day)
   V days = [‘Sunday’, ‘Monday’, ‘Tuesday’,
             ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’]
   V dooms = [[3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5],
              [4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]]

   V c = year I/ 100
   V r = year % 100
   V s = r I/ 12
   V t = r % 12
   V c_anchor = (5 * (c % 4) + 2) % 7
   V doomsday = (s + t + (t I/ 4) + c_anchor) % 7
   V anchorday = dooms[isleap(year)][month - 1]
   V weekday = (doomsday + day - anchorday + 7) % 7
   R days[weekday]

L(year, month, day) [(1800, 1, 6), (1875, 3, 29), (1915, 12, 7),
     (1970, 12, 23), (2043, 5, 14), (2077, 2, 12), (2101, 4, 2)]
   print(‘#.-#02-#02 -> #.’.format(year, month, day, weekday(year, month, day)))

  

You may also check:How to resolve the algorithm Program name step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Extensible prime generator step by step in the C++ programming language
You may also check:How to resolve the algorithm Sort an integer array step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Sexy primes step by step in the Scala programming language
You may also check:How to resolve the algorithm Smarandache prime-digital sequence step by step in the Nim programming language