Advertisement
Guest User

Untitled

a guest
Mar 20th, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. getClusterPositions :: Int -> Int -> [Elem] -> [Int]
  2. getClusterPositions _ _ [] = []
  3. getClusterPositions occur pos (Dot:Star:t)
  4. | occur == countStarSeq (Star:t) = (pos+1) : getClusterPositions occur (pos+2) t
  5. | otherwise = getClusterPositions occur (pos+2) t
  6. getClusterPositions occur pos (_:t) = getClusterPositions occur (pos+1) t
  7.  
  8. removeCluster :: Int -> Int -> [Elem] -> [Elem]
  9. removeCluster _ _ [] = []
  10. removeCluster occur _ (Dot:t) = Dot:removeCluster occur 0 t
  11. removeCluster occur index (Star:t)
  12. | (index + countStarSeq (Star:t)) == occur = Dot:(removeCluster occur (index+1) t)
  13. | otherwise = Star:(removeCluster occur (index+1) t)
  14.  
  15. occ :: [Elem] -> [(Int, [Int])]
  16. occ x
  17. | countStar x > 0 = (countStarSeq x, getClusterPositions (countStarSeq x) 0 (Dot:x)) : occ (removeCluster (countStarSeq x) 0 x)
  18. | otherwise = []
  19. countStarSeq :: [Elem] -> Int
  20. countStarSeq [] = 0
  21. countStarSeq (Star:Dot:t) = 1
  22. countStarSeq (Star:t) = 1 + countStarSeq t
  23. countStarSeq (Dot:t) = countStarSeq t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement