Skip to content

Instantly share code, notes, and snippets.

@jwosty
Last active September 25, 2016 23:14
Show Gist options
  • Save jwosty/a339a357979dbebbb745d21d57082def to your computer and use it in GitHub Desktop.
Save jwosty/a339a357979dbebbb745d21d57082def to your computer and use it in GitHub Desktop.
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