Created
September 29, 2015 04:04
-
-
Save sordina/350c6015e666f4971add 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
-- Clustering algorithm v2 | |
destroy _ E = E | |
destroy 1 (L _) = E | |
destroy _ (L x) = L x | |
destroy n x@(N l r) | count x == n = E | |
| count x > n = N (destroy n l) (destroy n r) | |
| otherwise = x | |
search _ E = [] | |
search 1 (L x) = [L x] | |
search _ (L x) = [] | |
search n x@(N l r) | count x == n = [x] | |
| count x > n = search n l ++ search n r | |
| otherwise = [] | |
expand n = takeWhile (> 0) $ concatMap ex [0..] where ex x = [n-x,n+x] | |
scanner (t,_) n = (destroy n t, search n t) | |
cluster n t = concatMap (map leaves . snd) $ scanl scanner (t,[]) (expand (count t `div` n)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment