Re: Collaborative golf.

[email protected] (Paul Johnson)
Newsgroups perl.golf
Message-ID <[email protected]>
On Sat, Sep 14, 2002 at 08:47:23AM +0100, Piers Cawley wrote:
> So, whilst rambling, I came upon the calculations required to work out
> the date of easter for a given year (Gregorian calendar). Here it is
> expressed in perl.
> 
>     my $year = pop;
>     my $G = $year%19;
>     my $C = int($year/100);
>     my $H = ($C - $C/4 - int((8*$C+13)/25) + 19*$G + 15) %30;
>     $I = $H - int($H/28)*(1 - int($H/28) * int(29/($H+1)) * int(21-$G/11));
>     $J = ($year + int($year/4) + $I + 2 - $C + int($C/4))%7;
>     $L = $I - $J;
>     $month = 3 + int(($L+40)/44);
>     $day = $L + 28 - 31 * int($month/4);
>     printf("%d%02d%02d\n", $year, $month, $day);
> 
> I'm sure we can do better. But how *much* better?
> 
> My current best effort stands at 212 chars (scored by wc), which I'll
> post later today, unless someone has already done better.
> 
> Kudos will be given to anyone who does it in a regex...

Here's one that doesn't come anywhere near Perl, but it does have nicer
output and error checking - in 240 chars.

echo `echo $* '[ddsf[lfp[too early]Pq]s@1583>@ddd19%1+sg100/1+d3*4/12-sx8*5+25/5-sz5*4/lx-10-sdlg11*20+lz+lx-30%d[30+]s@0>@d[[1+]s@lg11<@]s@25=@d[1+]s@24=@se44le-d[30+]s@21>@dld+7%-7+[March ]smd[31-[April ]sm]s@31<@psnlmPpsn1z>p]splpx'|dc`

(That's all one line if someone gets it wrapped, but it probably doesn't
matter too much.)

I believe that most of the credit for this should go to Fred Avolio.
I've had it knocking around since the late 80s I think.

-- 
Paul Johnson - [email protected]
http://www.pjcj.net
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.