28 lines
781 B
Text
28 lines
781 B
Text
{def BS
|
|
{def BS.r {lambda {:a :v :i0 :i1}
|
|
{let { {:a :a} {:v :v} {:i0 :i0} {:i1 :i1}
|
|
{:m {floor {* {+ :i0 :i1} 0.5}}} }
|
|
{if {< :i1 :i0}
|
|
then :v is not found
|
|
else {if {> {array.item :a :m} :v}
|
|
then {BS.r :a :v :i0 {- :m 1} }
|
|
else {if {< {array.item :a :m} :v}
|
|
then {BS.r :a :v {+ :m 1} :i1 }
|
|
else :v is at array[:m] }}}}} }
|
|
{lambda {:a :v}
|
|
{BS.r :a :v 0 {- {array.length :a} 1}} }}
|
|
-> BS
|
|
|
|
{def A {array 12 14 16 18 20 22 25 27 30}}
|
|
-> A = [12,14,16,18,20,22,25,27,30]
|
|
|
|
{BS {A} -1} -> -1 is not found
|
|
{BS {A} 24} -> 24 is not found
|
|
{BS {A} 25} -> 25 is at array[6]
|
|
{BS {A} 123} -> 123 is not found
|
|
|
|
{def B {array {serie 1 100000 2}}}
|
|
-> B = [1,3,5,... 99997,99999]
|
|
|
|
{BS {B} 100} -> 100 is not found
|
|
{BS {B} 12345} -> 12345 is at array[6172]
|