I’ve been playing around with various ways to write a function that
does a binary search on an array of integers.
Below is one of my implementations. I’m wondering if it is possible
to avoid passing the function to itself
in order to achieve the recursive call. While I’m defining the
function’s body, is there a special syntax to define
a recursive call to the function being defined?
I’m also interested in any feedback folks may have to offer regarding
the below implementation.
Thanks,
Steven
Attempts to locate “int” in “int_array”
if “int” is found, this function will return
the index of “int’s” location. If “int” is not
found, this function will return -1. This function
I’ve been playing around with various ways to write a function that
does a binary search on an array of integers.
Below is one of my implementations. I’m wondering if it is
possible to avoid passing the function to itself
in order to achieve the recursive call.
You don’t need one.
% cat recursion_diversion.rb
func = lambda do |x|
if x == 0
puts “Recursing”
func.call(1)
else
puts “Done”
end
end
}
Sweet! Y-Combinator in ruby. You do realize, now that you’ve done the
“hard part” what this will do to advance the state of the art in ruby
obfuscation?
Sweet! Y-Combinator in ruby. You do realize, now that you’ve done the
“hard part” what this will do to advance the state of the art in ruby
obfuscation?
yawn. BTDT:
-rw-rw-r-- 1 chris chris 222 Oct 25 2003
/Users/chris/projects/ruby/y.rb
-rw-rw-r-- 1 chris chris 285 Oct 25 2003
/Users/chris/projects/ruby/jarh2.rb
s=“,GreEkcaSh BODybuILDER ALBreChtAMMOonIa tSUNEMATsuJ”;
puts lambda{|f|h=lambda{|h|lambda{|x|f[h[h]][x]}};h[h]}[
lambda{|f|lambda do|h|h[0]?f[h[1…-1]]<<h[0]:[];end}][s.
delete(*%w{A-Z ^JR})].#See King James text of the bible:
pack(“c*”)## “Y do ye not understand my speech?”, John 8
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.