From: Tim Hunter Date: 2007-11-11T23:21:16+09:00 Subject: Re: The Man or Boy Recursion Test Lloyd Linklater wrote: > Tim Hunter wrote: >> Werner wrote: >>> Is there anyone who could enlighten me? >>> >>> Thanks and Best Regards >>> >>> Werner Dahn >>> >> # Man or boy test >> def a(k, x1, x2, x3, x4, x5) >> b ||= Proc.new { k -= 1; a(k, b, x1, x2, x3, x4) } >> return k <= 0 ? x4[] + x5[] : b[] >> end >> >> puts a(10, Proc.new {1}, Proc.new {-1}, Proc.new {-1}, Proc.new {1}, >> Proc.new {0}) > > Nice post, Tim. I tested it and, when it gave the correct answer, I > decided to share it with the world. > > http://en.wikipedia.org/wiki/Man_or_boy_test Sweet! I realized last night that the ||= is superfluous. A simple assignment is enough. b = Proc.new { k -= 1; a(k, b, x1, x2, x3, x4) } -- RMagick OS X Installer [http://rubyforge.org/projects/rmagick/] RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?forum_id=1618] RMagick Installation FAQ [http://rmagick.rubyforge.org/install-faq.html]