SHARE
TWEET

Untitled

a guest Mar 26th, 2020 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. num = Array.new(1000000) { |i| i+=1 }
  2. find = 1000
  3.  
  4.  
  5. def binary(array, find, start=0, final=nil)
  6.     if final.nil?
  7.         final = array.size - 1
  8.     end
  9.    
  10.     if start > final
  11.         puts "item not found"
  12.         exit
  13.     end
  14.  
  15.     half = (start+final) / 2
  16.  
  17.     if array[half] != find
  18.         if array[half] < find
  19.             start = half +1
  20.         else
  21.             final = half -1
  22.         end
  23.         return binary(array, find, start, final)
  24.     end
  25.  
  26.     puts array[half]
  27. end
  28.  
  29. binary(num, find)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top