lean4-htt/tests/lean/binsearch.lean
2020-09-13 13:44:05 -07:00

15 lines
460 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

new_frontend
partial def mkAssocArray : Nat → Array (Nat × Bool) → Array (Nat × Bool)
| 0, as => as
| i+1, as => mkAssocArray i (as.push (i, i % 2 == 0))
def tst (n : Nat) : IO Unit :=
do
let as := mkAssocArray n Array.empty;
IO.println as;
let as := as.qsort (fun a b => a.1 < b.1);
(2*n).forM $ fun i => do
let entry := as.binSearch (i, false) (fun a b => a.1 < b.1);
IO.println (">> " ++ toString i ++ " ==> " ++ toString entry)
#eval tst 10