Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- binSearch :: Integral i => (i -> Bool) -> i -> i -> i
- binSearch f = go where
- go l h
- | l > h = l
- | f m = go l (m - 1)
- | otherwise = go (m + 1) h
- where m = (l + h) `div` 2
- binSearchA :: (a -> Bool) -> Array Int a -> Int
- binSearchA f a = binSearch (f . (a!)) l h where (l, h) = bounds a
Add Comment
Please, Sign In to add comment