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.

  • Magic Day

    Math wizards amaze audiences by naming the day of the week for any date called out by the audience. Mike Schilli writes a training program in Go to turn amateurs into headline performers.

  • Perl: Portfolio Watch

    We'll show you a Perl script that helps you draw area graphs to keep track of your portfolio's performance.

  • Programming Snapshot – Mileage AI

    On the basis of training data in the form of daily car mileage, Mike Schilli's AI program tries to identify patterns in driving behavior and make forecasts.

  • Tutorial – Shell Scripting

    You do not need to learn low-level programming languages to become a real Linux power user. Shell scripting is all you need.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News