interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / exercises / binary-search / .meta / example.om

23 lines · 543 bytes Raw Blame History
1note Exercism-style exercise "binary-search": https://exercism.org/tracks/python/exercises/binary-search
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note find is the index of v in the ascending array a, found by binary search, or -1 when v is not
4note in a.
5note Check it with: sh exercise.sh exercises/binary-search
6om2
7fn find a view ulong * v ulong to long
8lo = ulong 0
9hi = len a
10while lt lo hi bound 64
11m = add lo div sub hi lo 2
12x = get a m
13if eq x v
14ret long m
15end
16if lt x v
17lo = add m 1
18else
19hi = m
20end
21end
22ret -1
23end