Perl Christmas Quiz 2009 Answers

Chris Jack chris_jack at msn.com
Wed Dec 9 13:20:54 GMT 2009


I thought I should (again) post some sample answers. The challenge of writing a Xmas quiz is always coming up with short, interesting questions that touch on interesting and potentially controversial answers. I spent the better part of a year coming up with the questions I did, and, to be honest, I will only know next year at the same time whether I am able to come up with any more.

As with last year, I have found that the original answers I had invisaged have had to be modified in view of people who had better knowledge than I did. I didn't realise the answer to question 1 was dependent on the version of perl used. I still don't know how to better word question 7 and am curious to know if there is a better way of doing it - but I believe my proposed answer is in keeping with the spirit of doing the calculation in the regular expression engine.

I find it interesting when people propose psychic insights into my inability to know the correct answer to questions (I'm thinking question 6 here) - but I will hold my hand up and plead "gotten". I think my answer to question 10 may cause controversy, but it is based on a careful reading of the sited webpage.

Anyway: enough chit chat:
 
--------
 
1) Without running it to check, what does the following program output?

my %a = (3,2,1,0);
for my $b (sort values %a) {
 $b += 4;
}
print $a{1} . "\n";

Answer: 4
 
--------
 
2) If you received a perl mongers award for contributions to the Perl
community, what colour/type of camel would the award be?

Answer: A white (albino) camel.
 
--------

3) What is Perl XS? What does XS stand for?

Answer: It's an interface through which a Perl program can call a C or C++ subroutine. XS stands for eXternal Subroutine.
 
--------
 
4) Based on your answer to the previous question, what do you conclude about
Perl programmers spelling ability?
 
Answer: It's so 1990's
 
--------

5) Write a short perl program that has a memory leak. Bonus mark for one line
solutions. Second bonus mark for the shortest program.

Answer:
 
{my $a;$a=\$a}
 
I thought the proposed:
 
valgrind perl -e''
 
was interesting, but surely this is a bug not a language feature.
 
--------

6) What is the name of the official Soft Toy Camel of the London Perl Mongers?
Bonus mark if you own one.

Answer: Amelie/Niles - the latter possibly because having him on your desk has a Seinfeld-esque therapeutic effect. It just keeps staring at me with those piercing black eyes: does it think I'm going to crack and open up?
 
--------

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.
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.

Answer:

("1" x $ARGV[0]) =~
/
^(1*?)(??{$1 x (length($1) - 1)})$
(?{ print "x=" . length($1) . "\n" })
/x;

% time root.pl 10000
x=100
real    0m0.685s
user    0m0.045s
sys     0m0.030s
% time root.pl 10001
real    670m14.985s
user    659m58.285s
sys     1m34.659s

The first question mark is critical to an efficient solution as it is effectively looking for a solution by counting up from 0 rather than down from the given number.
 
--------
 
8) According to amazon.co.uk, what is the best selling Perl book so far in 2009?

Answer:
Learning Perl by Randal Schwartz, Tom Phoenix, brian foy. See:
http://www.amazon.co.uk/gp/bestsellers/books/269855/ref=pd_zg_hrsr_b_2_5_last

This is actually a bad question as Amazon's best seller list algorithm is not year to date sales. Here are some discussions:

http://comiksdebris.blogspot.com/2009/08/amazon-best-seller-list-black-box-with.html 
http://www.guardian.co.uk/science/2009/feb/23/algorithms-internet-google-amazon-itunes

--------

9) What is the youtube.com link for the perl v other languages videos
discussed on this list, and also the bubble sort video?

Answer: Urgle: we should make this happen.

--------

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

Answer: 8 see http://www.perl.com/download.csp

--------

11) Think of a witty and/or interesting Perl Christmas quiz question and
answer it.

Answer:

while (1) {
print "Think of a witty and/or interesting Perl Christmas quiz question and answer it.\n";
}
print "It didn't say it hard to be original\n";

 

Randal now owes me 2 pints of beer as he has featured in both my Xmas quizzes.
Leon owes me 1.5 pints for similar reasons.

Apologies for any inappropriate thread reply management. Hotmail is now so "advanced", it doesn't even allow me to look at the full email header.

Chris 		 	   		  
_________________________________________________________________
Use Hotmail to send and receive mail from your different email accounts
http://clk.atdmt.com/UKM/go/186394592/direct/01/


More information about the london.pm mailing list