Jump to content

Binary search: Difference between revisions

(Add bruijn)
Line 2,519:
{ p "Not found" }
{ p "Found at index: #{index}" }</syntaxhighlight>
 
=={{header|Bruijn}}==
As defined in <code>std/Combinator</code>:
<syntaxhighlight lang="bruijn">
:import std/Number .
 
# sage bird combinator
y [[1 (0 0)] [1 (0 0)]]
 
# factorial using y
factorial y [[=?0 (+1) (0 ⋅ (1 --0))]]
 
:test ((factorial (+6)) =? (+720)) ([[1]])
 
# (very slow) fibonacci using y
fibonacci y [[0 <? (+1) (+0) (0 <? (+2) (+1) rec)]]
rec (1 --0) + (1 --(--0))
 
:test ((fibonacci (+6)) =? (+8)) ([[1]])
</syntaxhighlight>
 
=={{header|C}}==
55

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.