Subject: Perl Golf

From: Shlomi Fish <[email-masked]>
Date: Tue, 27 May 2003 14:21:54 +0300 (IDT)

Perl Golf are types of competitions in which competitors attempt to write
the shortest Perl program (character-wise) that will accomplish a certain
task. This evidently creates some really short and obfuscated solutions.

It started out with Usenet and mailing lists discussions in which people
tried to come up with the shortest Perl program. Eventually, it was
institutionalized as Perl Golf competitions:

http://perlgolf.sourceforge.net/

At the moment most of the golfing activity is present in the Minigolf
site:

http://terje.perlgolf.org/

I took part in some of the mini-golf competitions and I could testify that
they are very fun and highly addictive. You keep staring at the code
trying to eliminate more and more characters and are puzzled by the
scores that the people above you have reached. I keep reading the Perl man
pages (perlfunc, perlre, perlop, perlvar, perlrun, etc.) looking for
things that may make my program shorter, and keep learning new things
about Perl.

Reading the solutions of other people also give a lot of insights.

Regards,

	Shlomi Fish

----------------------------------------------------------------------
Shlomi Fish        [email-masked]
Home Page:         http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

	Falk Fish

---

From: Shlomi Fish <[email-masked]>
Date: Wed, 28 May 2003 16:59:28 +0300 (IDT)

And here's a classic snippet to print "Prime" if a number is prime:

perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'

Taken from:

http://ucan.foad.org/~abigail/Perl/Talks/Japhs/primes2.html

Regards,

	Shlomi Fish

	Falk Fish

---

From: "Nadav Har'El" <[email-masked]>
Date: Wed, 28 May 2003 17:07:55 +0300

> perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'

It's an interesting example of how short regular expressions, especially
when they include Perl extensions, can have abysmal, expontential,
performance...

On my system, finding that 45677 is prime took 1.352 seconds (compare
to 0 seconds for "factor 45677"). Giving this perl program the number
"65535" dumped core.

In short, nice trick but it should be obvious it's not useful at all for
anything but tiny numbers.

-- 
Nadav Har'El                        |    Wednesday, May 28 2003, 26 Iyyar 5763
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |A Nobel Peace Prize? I would KILL for one
http://nadav.harel.org.il           |of those.