Skip to content

Instantly share code, notes, and snippets.

@rajatsharma
Created September 15, 2017 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajatsharma/334d16dda8bdbac74bcc3d3b63b18e3a to your computer and use it in GitHub Desktop.
Save rajatsharma/334d16dda8bdbac74bcc3d3b63b18e3a to your computer and use it in GitHub Desktop.
Binary Search in Haskell
bsearch _ [] = "Not Found"
bsearch e xs
| e < mid xs = bsearch e (take (mid xs - 1) xs)
| e > mid xs = bsearch e (drop (mid xs + 1) xs)
| otherwise = mid xs
where
mid ls = (length ls `div` 2) :: Int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment