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.call(); } }
pong = { if( i ) { evaluate(bonk); ping.call(); } }
ping.call()

No comments: