Skip to content

Instantly share code, notes, and snippets.

@jwosty
Last active September 25, 2016 23:14
Show Gist options
  • Save jwosty/f6f5d8ef0b1509f7fbd87aacbc08cb7f to your computer and use it in GitHub Desktop.
Save jwosty/f6f5d8ef0b1509f7fbd87aacbc08cb7f to your computer and use it in GitHub Desktop.
let rec genPairs list =
match list with
| [] -> []
| x::ys -> [for y in ys -> x, y] @ genPairs ys
let items = ["joe"; "jim"; "jack"; "jud"]
let r = new System.Random()
let shuffle cards = cards |> List.map (fun card -> r.Next(),card) |> List.sort |> List.map snd
items |> shuffle
let rec dealPairs pairs =
match pairs with
| [] -> []
| (x1,x2)::rest ->
let withoutx1x2 =
List.filter (fun (rest1, rest2) ->
rest1 <> x1 && rest1 <> x2 && rest2 <> x1 && rest2 <> x2)
rest
(x1,x2) :: dealPairs withoutx1x2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment