RSS

How to detect Friday the 13th with full moon using Emacs

12 Nov

nrAlmost 21 years ago, in 1994, I bought the brand new edition of Numerical Recipes in C: The Art of Scientific Computing. As an engineering and mathematics student who was much into programming, I still remember my excitement then, as well as the bright red hard-cover.

The first algorithm presented in the book (and its implementation in C programming language) was about calculating the dates that were Friday the 13th and had full moon. Now that I’m approaching the 21st anniversary of that day, I wanted to share a similar program to detect if the current date is Friday the 13th with full moon. This time, my preference is for Emacs Lisp, and instead of re-implementing the same algorithm, I simply use the calculations already provided by Emacs. In other words, I rely on the lunar-phase-list function that returns the lunar phases of the upcoming dates given a month and a year.

It’s been ages since I’ve done Common Lisp programming and many years since I’ve practiced Emacs Lisp, so the code below is probably not optimal and idiomatic, but nevertheless it follows:

You can used the function defined above to see whether it is your “unlucky” day:

This will return “Good luck!” most of the time, luckily!🙂

Can you come up with other ways of detecting Friday the 13th with full moon using existing utilities, such as GNU calendar program? Or, how would you calculate the next 10 Friday the 13ths that had full moon, using Emacs Lisp or some existing utility?

 

 
Leave a comment

Posted by on November 12, 2015 in Emacs, Lisp, Programlama

 

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: