Binary search: Difference between revisions
m
→{{header|Chapel}}
(Add bruijn) |
LalaithMeren (talk | contribs) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 2,521:
=={{header|Bruijn}}==
<syntaxhighlight lang="bruijn">
:import std/
:import std/Math .
:import std/List .
:import std/Option .
binary-search [y [[[[[2 <? 3 none go]]]]] (+0) --(∀0) 0]
eq some 0
lt 5 4 --0 2 1
gt 5 ++0 3 2 1
# example using sorted list of x^3, x=[-50,50]
lst take (+100) ((\pow (+3)) <$> (iterate ++‣ (-50)))
:test (
:test ((head (find (+117649))) =? (+99)) ([[1]])
▲:test ((fibonacci (+6)) =? (+8)) ([[1]])
</syntaxhighlight>
Line 2,889 ⟶ 2,891:
'''iterative''' -- almost a direct translation of the pseudocode
<syntaxhighlight lang="chapel">proc binsearch(A : [], value)
{
var
while (low <= high)
{
var mid = (low + high) / 2;
Line 2,909 ⟶ 2,913:
{{out}}
4
=={{header|Clojure}}==
'''Recursive'''
|