Perl Christmas Quiz 2009

Abigail abigail at
Mon Nov 30 21:02:03 GMT 2009

On Mon, Nov 30, 2009 at 06:24:12PM +0000, Chris Jack wrote:
> Seeing as last year's quiz was mildly popular, I thought I'd do another
> one. I've changed the mix of questions based on what people submitted
> answers to last year - it also arguably a little more educational this
> time around.
> Any feedback about the quiz, either private or public is
> welcome. Apologies if any of it doesn't come out well formatted - it
> all looked fine before I hit send.
> 5) Write a short perl program that has a memory leak. Bonus mark for one line
> solutions. Second bonus mark for the shortest program.

valgrind claims the shortest possible perl program leaks 5 bytes:

   $ valgrind perl -e''
   ==19803== LEAK SUMMARY:
   ==19803==    definitely lost: 5 bytes in 1 blocks.
   ==19803==      possibly lost: 0 bytes in 0 blocks.
   ==19803==    still reachable: 82919 bytes in 623 blocks.
   ==19803==         suppressed: 0 bytes in 0 blocks.


> 7) Write a one line program that takes a non-negative integer as an argument
> and prints the square root when the answer's an integer.
> Restrictions: the perl line should be a regular expression.

Just a regular expression? Regular expressions don't print, so that would
be impossible.

> You are allowed to use the following functions/operators "x", "-", "length",
> "print" plus any of the usual regular expression bestiary.
> Hint: Consider converting the number to unary.

Perhaps you want a regular expression that determines whether a number
a prime. I think that's either trivial, or impossible, depending on
the restriction. If we may use (?{ })/(??{ }), it's trivial, because 
that means we can do any you can do in ordinary Perl.

With being allowed to execute Perl code, I do not think it to be possible -
I've been trying to achieve that on and off for years. Even if with (named)
rules, I believe it to be impossible. AFAIK, the set of all strings of a
unary alphabet whose length is a square cannot be recognized by a PDA - and
I don't think backreferences are powerful enough to bridge this gap.

Of course, one could cheat and write a regular expression that just lists
all the square numbers 1 .. MAX_INT. But I don't think that's the solution
you're after. 

> 10) What is the highest value of X that is a currently available, stable
> production release of perl 5.X?

According to perlhist, that would be X = 001m: 5.001m is the most recent
perl it claims to be 'stable' or 'very stable'.


More information about the mailing list