月齢を計算する

#!/usr/bin/env perl

use Time::Piece;

@value = (0, 0, 2, 0, 2, 2, 4, 5, 6, 7, 8, 9, 10);

$time = localtime;

print $time->strftime(),"\n";

$the_age_of_the_moon = ((($time->year - 11) % 19) * 11 + $value[$time->mon] + $t
ime->mday) % 30;

print "The age of the moon: $the_age_of_the_moon\n";


今日の月齢は?

$ ./the_age_of_the_moon.pl 
Fri, 06 Apr 2012 23:40:03 JST
The age of the moon: 14


参照したページ:
wikipedia:月齢


2012.04.07 追加

$ ./the_age_of_the_moon.pl 
Sat, 07 Apr 2012 00:02:21 JST
The age of the moon: 15