Created
July 31, 2015 13:36
-
-
Save nobsun/ae8ad155d20fa477abb1 to your computer and use it in GitHub Desktop.
続・順列列挙関数 ref: http://qiita.com/nobsun/items/232b7e61d4d0905522af
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
perms :: [a] -> [[a]] |
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
perms [] = [[]] |
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
perms xs@(_:_) = concat (zipWith prefix xs (map perms (shorts xs))) |
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
perms :: [a] -> [[a]] | |
perms [] = [[]] | |
perms xs@(_:_) = concat (zipWiht prefix xs (map perms (shorts xs))) | |
prefix :: a -> [[a]] -> [[a]] | |
prefix = undefined | |
shorts :: [a] -> [[a]] | |
shorts = undefined |
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
prefix x = map (x:) |
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
shorts xs = unfoldr phi ([],xs) | |
where | |
phi (_,[]) = Nothing | |
phi (ys,z:zs) = Just (ys++zs,(ys++[z],zs)) |
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
perms :: [a] -> [[a]] | |
perms [] = [[]] | |
perms xs@(_:_) = concat (zipWiht prefix xs (map perms (shorts xs))) | |
prefix :: a -> [[a]] -> [[a]] | |
prefix x = map (x:) | |
shorts :: [a] -> [[a]] | |
shorts xs = unfoldr phi ([],xs) | |
where | |
phi (_,[]) = Nothing | |
phi (ys,z:zs) = Just (ys++zs,(ys++[z],zs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment