From: Johnny Morrice Date: 2011-05-06T21:01:43+09:00 Subject: Re: Lets play a guessing game. (how to code this better?) > You could even try to solve it with the functional pradigm. That's not functional enough for me ;) In case the syntax gets chewed: http://pastie.org/1871414 # Z combinator defines explicit recursion Z = lambda { |f| (lambda {|x| f.call(lambda {|*ys| x.call(x).call(*ys)})}).call(lambda {|x| f.call(lambda {|*ys| x.call(x).call(*ys)})})} # The guess combinator holds a reference to itself in the 'again' variable Guess = lambda do |again| lambda do |magic| print "Choose 0-100> " n = gets.to_i if !(0..100).include?(n) puts "0-100!" next end puts "Higher!" if nmagic if n==magic puts "You won: #{magic} is the number!" else again.call magic end end end magic = rand(101).to_i puts "Guess the magic number!" Z.call(Guess).call(magic) Clearly this is the most obvious solution. Cheers, Johnny