Friday, August 24, 2007

Groovy Puzzler: Ping Pong

I'm borrowing a "Friday puzzler" theme from Weiqi Gao.

This puzzler is in my "language of the week": Groovy. It didn't make my list in the thought experiment Seven Wonders, but it is a charming language, especially for Java developers.

What's the output from this program? Assume an argument is passed on the commandline.

i = args[0].length()
bonk = 'println args[0][i---1]'
ping = { if( i ) { evaluate(bonk);; } }
pong = { if( i ) { evaluate(bonk);; } }

No comments: