Created
July 28, 2014 13:24
-
-
Save loosechainsaw/c1223ce5ad896ab95df4 to your computer and use it in GitHub Desktop.
Code Dojo 1 - F# Implementation of Binary Search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Algorithms = | |
let binary_search list value = | |
let rec impl(list: 'a list) (value :'a) (hi: int) (low:int) = | |
let index = (hi + low) / 2 | |
match compare value (list.Item(index)) with | |
| 0 -> Some(index) | |
| 1 -> impl list value hi index | |
| -1 -> impl list value index low | |
| _ -> None | |
match list with | |
| [] -> None | |
| _ -> impl list value (List.length list) 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment