RSS / Atom

Last Friday's puzzle

2003-07-15 , ,

Vadim asked the following brain teaser:

 How many squares are there on a chess board?
Yes, it’s a trick question but the solutions were better than the question or the answer.

Ik came up with a solution in Emacs Lisp:

(let ((f (lambda (n) (cond ((= n 1) 1) (t (+ (* n n) (f (1- n)))))))) (f 8))

Bill came up with one using DC, the RPN desk calculator, that just floored us and had us running to read the man pages:

echo "8sc0sr[q]sb[lc0lc=bd*lr+srlc1-sclax]salaxlrpq" | dc
Look closely at that one and think through it. Clever. Clever. The underlying simplicity is brilliant.

Based on Bill’s and Ik’s I cobbled together an obfuscated answer in Perl (save to a file, shell quoting mungs it):

#!perl -e $/=$@;$;=8;sub'f{$/+=$;--**2;$;}sub'g{&f&&&g}g;print$/$^L
Like theirs, it uses recursion but I try to hide what’s going because I am not clever.


Commenting is closed for this article.