Last active
December 14, 2015 21:18
-
-
Save khibino/5149966 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
import Data.List (isPrefixOf) | |
import Data.Set (Set) | |
import qualified Data.Set as Set | |
data K' = K0 | K1 | |
deriving (Show, Eq, Ord) | |
data K = Unit K' | |
| Str !String | |
deriving Show | |
instance Eq K where | |
Str _ == Str _ = True | |
Str _ == Unit _ = False | |
Unit _ == Str _ = False | |
Unit a == Unit b = a == b | |
-- instance Ord K where | |
-- Str _ < Str _ = False | |
-- Str _ < Unit _ = False | |
-- Unit _ < Str _ = True | |
-- Unit a < Unit b = a < b | |
instance Ord K where | |
Str _ `compare` Str _ = EQ | |
Str _ `compare` Unit _ = LT | |
Unit _ `compare` Str _ = GT | |
Unit a `compare` Unit b = a `compare` b | |
kOfString :: String -> K | |
kOfString = d where | |
d str | |
| "0" `isPrefixOf` str = Unit K0 | |
| "1" `isPrefixOf` str = Unit K1 | |
| otherwise = Str str | |
type Key = K | |
datas :: [Key] | |
datas = cycle $ map (kOfString . show) ([0,0,1,0,1,1,0,0,0,1] :: [Int]) | |
ngroup :: Int -> [a] -> [[a]] | |
ngroup n = rec where | |
rec xs = hd : rec xs' where | |
(hd, xs') = splitAt n xs | |
chunks :: [[[Key]]] | |
chunks = ngroup 5 . ngroup 3 $ datas | |
maps :: [Set Key] | |
maps = map (Set.unions . map Set.fromList) chunks | |
run :: [Set Key] | |
run = take 10 maps | |
main :: IO () | |
main = mapM_ print run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment