[EMAIL PROTECTED] (Bill -OSX- Jones) writes:
>I was asked recently if I could write a Perl program that
>would find out when the next time Christmas day would
>actually be on a Sunday.

>I came up with a recursive `cal 12 $year` Unix/Perl
>script [...]

>       Is there a better Perl Golf way?

You could try golfing on this algorithm (left relatively readable):

#!perl -l
$y=4-16*shift;$y+=(6,11,6,5)[$x++%4]until$y>(localtime)[5];print$y+1900

This takes a day number argument (0=Sunday to 7=Sunday); just remove
'-16*shift' to get a Sunday-only version. It won't print the current
year even if it fits, and it's only valid if run between 1900-01-01
and 2089-12-31 (2094-12-31 for Sundays only).

Lars Mathiesen (U of Copenhagen CS Dep) <[EMAIL PROTECTED]> (Humour NOT marked)

Reply via email to