Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Binary-search/Futhark/binary-search.futhark
Normal file
13
Task/Binary-search/Futhark/binary-search.futhark
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
fun main(as: [n]int, value: int): int =
|
||||
let low = 0
|
||||
let high = n-1
|
||||
loop ((low,high)) = while low <= high do
|
||||
-- invariants: value > as[i] for all i < low
|
||||
-- value < as[i] for all i > high
|
||||
let mid = (low+high) / 2
|
||||
in if as[mid] > value
|
||||
then (low, mid - 1)
|
||||
else if as[mid] < value
|
||||
then (mid + 1, high)
|
||||
else (mid, mid-1) -- Force termination.
|
||||
in low
|
||||
Loading…
Add table
Add a link
Reference in a new issue