On Thu, Feb 07, 2002 at 09:16:55AM -0000, Lars Henrik Mathiesen wrote:
> [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.
> 
> 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).

Or this:

#!perl -l
$_=shift;1while++$_,/(.+)(..)/,(8+$2*5/4-2*($1%4))%7;print

This doesn't take a day number, but does work for all years from 1748
onwards given a year as argument.  It won't print the starting year
even if it fits.

-- 
Matthew Winn ([EMAIL PROTECTED])

Reply via email to