Last active
September 25, 2016 23:14
-
-
Save jwosty/a339a357979dbebbb745d21d57082def to your computer and use it in GitHub Desktop.
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
let rec pairs list = | |
match list with | |
| [] -> [] | |
| x::ys -> [for y in ys -> x, y] @ pairs ys | |
pairs [1..4] | |
let rec pairslc list = [ | |
match list with | |
| [] -> () | |
| x::ys -> for y in ys do yield x, y | |
yield! pairslc ys ] | |
pairslc [1..4] | |
let rec firstFastPairs list acc = | |
match list with | |
| [] -> acc | |
| x::ys -> | |
firstFastPairs ys (List.fold (fun acc y -> (x,y)::acc) acc ys) | |
firstFastPairs [1..4] [] |> List.rev | |
let fastPairs list = | |
let rec fastPairs acc list = | |
match list with | |
| [] -> acc | |
| x::ys -> fastPairs (List.fold (fun acc y -> (x,y)::acc) acc ys) ys | |
fastPairs [] list | |
fastPairs [1..4] |> List.rev | |
let rec dealPairs candidates = | |
match candidates with | |
| [] -> [] | |
| [a] -> [a,None] | |
| a::b::rest -> (a, Some b)::(dealPairs rest) | |
dealPairs [1..4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment