Advertisement
kburnik

Logo - Binarna pretraga

Oct 27th, 2012
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. to binarno :s :e :p :n :cmp
  2.  
  3. while [ (:e-:s) > :p ] [
  4. localmake "t (:s+:e)/2
  5. localmake "usp run (list :cmp :t :n)
  6. ifelse ((abs :usp) <= :p) [
  7. op :t
  8. ][
  9. ifelse :usp < 0 [
  10. make "s :t
  11. ] [
  12. make "e :t
  13. ]
  14. ]
  15. ]
  16.  
  17. op :t
  18.  
  19. end
  20.  
  21. to usp :t :n
  22. op (:t*:t - :n)
  23. end
  24.  
  25. to korijen :n
  26. op binarno 1 :n 0.0000000001 :n "usp
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement