Created
May 13, 2019 19:49
-
-
Save vba/1669ac1254326715dc4237242e0a2990 to your computer and use it in GitHub Desktop.
This file contains 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 fusionNeighbours (accumulator: int Set list) (neighbour: int Set) = | |
match accumulator with | |
| [] -> [neighbour] | |
| head :: tail -> | |
let intersect = neighbour |> Set.intersect | |
match (head |> intersect).Count with | |
| 2 -> (head |> (Set.union neighbour)) :: tail | |
| _ -> neighbour :: accumulator | |
let collection = [ | |
[1; 2; 3] |> Set.ofList | |
[3; 4; 5] |> Set.ofList | |
[4; 5; 6] |> Set.ofList | |
[8; 9; 11] |> Set.ofList | |
[9; 10; 11] |> Set.ofList | |
] | |
collection | |
|> Seq.fold fusionNeighbours List.Empty | |
|> Seq.rev | |
|> printfn "Result: %A" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about this one: