Perl script reveals math trick

MIND GAMES

Article from Issue 87/2008
Author(s):

A trick that anybody can learn lets you determine the day of the week from the date. We’ll apply some Perl technology to discover whether the method is reliable.

Recently, I was reading Mind Performance Hacks and stumbled across Hack Number 43, which explains how to determine the day of the week for any given date. The method is attributed to Lewis Carroll], the author of Alice’s Adventures in Wonderland. Simply calculate four values, one after the other, for the year, month, and day, and a fourth value as an adjustment factor. Then add the values, divide by 7, and the remainder amazingly gives you the day of the week as a number between zero (Sunday) and six (Saturday).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Perl: DateTime Module

    Because calendar rules are influenced by historical and political decisions, date manipulations are riddled with pitfalls. Perl’s DateTime module knows all the tricks.

  • Command Line: cal and date

    The legacy cal and date tools help users keep track of the time and date. You can even change the system time with a single shell command.

  • Perl: Automating Color Correction

    If you have grown tired of manually correcting color-casted images (as described in last month's Perl column), you might appreciate a script that automates this procedure.

  • Perl: Tricks with Vim

    The Vim editor has any number of tricks for helping you avoid unnecessary typing. In this month’s article, we look at some effort-saving Vim techniques for Perl hackers.

  • Letters
comments powered by Disqus

Direct Download

Read full article as PDF:

078-080_perl.pdf  (399.36 kB)

News

njobs Europe
What:
Where:
Country:
Njobs Netherlands Njobs Deutschland Njobs United Kingdom Njobs Italia Njobs France Njobs Espana Njobs Poland
Njobs Austria Njobs Denmark Njobs Belgium Njobs Czech Republic Njobs Mexico Njobs India Njobs Colombia