Git Product home page Git Product logo

doomsday's Introduction

doomsday.py: a Doomsday rule trainer

Overview

A simple command line utility implemented in Python for practicing mental calculation of the day of the week for dates in the Gregorian calendar, using the Doomsday rule algorithm originally described by John Horton Conway [1]. This implementation relies on recent improvements to the algorithm by Chamberlain Fong and Michael K. Walters [2] that reduce the complexity of the mental calculation, as well as on the formula for calculating the anchor day for a century described in the Wikipedia entry for the Doomsday rule [3].

Requirements

Python 2.6 or later.

Installation

$ git clone https://github.com/bradleypallen/doomsday.git
$ cd doomsday
$ chmod +x *.py

Usage

$ ./doomsday.py
Type 'q' to quit, 0 - 6 to enter the day of the week.
February 8th, 1858? 6
Wrong! February 8th, 1858 fell on a Monday.
1) Calculate the anchor day for the 19th century.
doomcentury = ((5*19 + floor(18/4)) mod 7 + Thursday) mod 7
            = ((95 + 4) mod 7 + Thursday) mod 7
            = (99 mod 7 + 4) mod 7
            = (1 + 4) mod 7
            = 5 mod 7
            = 5
2) Calculate the doomsyear for year 58 in the century.
doomsyear   = 7's complement of ((58/2)+11 mod 7)
            = 7's complement of (40 mod 7)
            = 7's complement of 5
            = 2
3) Calculate the doomsmonth for February of the year.
1858 was not a leap year, so February 21st, 1858 fell on a Doomsday.
doomsmonth  = 8 - 21
            = -13
4) Calculate the day of the week.
day of week = (doomscentury + doomsyear + doomsmonth) mod 7
            = (5 + 2 + -13) mod 7
            = -6 mod 7
            = 7's complement of (6 mod 7)
            = 7's complement of 6
            = 1
            = Monday
August 29th, 2129? 1
Correct! August 29th, 2129 falls on a Monday.
March 9th, 2580? q
Accuracy = 50% over 2 trials

License

This code is provided under the terms of an MIT License [4]. See the LICENSE file for the copyright notice.

References

[1] Berlekamp, E.R., Conway, J.H. and Guy, R. K. Winning Ways for your Mathematical Plays. Volume 2: Games In Particular. Academic Press, NY (1982).

[2] Fong, C. and Walters, M.K. Methods for Accelerating Conway's Doomsday Algorithm (part 2). ICIAM (2011).

[3] Wikipedia. Doomsday rule. Downloaded from http://en.wikipedia.org/wiki/Doomsday_rule (2012).

[4] Open Source Initiative (OSI). The MIT License. Downloaded from http://www.opensource.org/licenses/mit-license.php (2012).

doomsday's People

Contributors

bradleypallen avatar devinzuck avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.