From: Matthew Kerwin Date: 2013-04-15T11:47:16+09:00 Subject: Re: simple lambda question Hyun Oh K. wrote in post #1105634: > below is python code. [snip] > and ruby have lambda func. so I hope easly solution make. > anybody wellknown ruby user, help and solve above quiz. You don't need lambdas to do this. If you want to start simply, why not just translate the python directly to ruby? $ irb irb:001:0> a=0 => 0 irb:002:0> while a*a < 10000 irb:003:1> if a*a > 1000 irb:004:2> s = (a*a).to_s irb:005:2> if s[0]==s[1] and s[2]==s[3] irb:006:3> puts "#{a}, #{a*a}" irb:007:3> end irb:008:2> end irb:009:1> a = a+1 irb:010:1> end 88, 7744 => nil The next idiomatic step would be to use ruby's more functional block methods. As far as I understand it these aren't actually lambdas as such, but I guess that's what you were talking about. You can also inline the inner-most `if' pretty easily as well. $ irb irb:001:0> 100.times do |a| irb:002:1* if a*a > 1000 irb:003:2> s = (a*a).to_s irb:004:2> puts "#{a}, #{s}" if s[0]==s[1] and s[2]==s[3] irb:005:2> end irb:006:1> end 88, 7744 => 100 There's not much more I'd do with this particular snippet. -- Posted via http://www.ruby-forum.com/.