Last active
December 26, 2015 17:09
-
-
Save craigjbass/7185255 to your computer and use it in GitHub Desktop.
Give all possible permutations given a list of lists such that each list defines the set of characters for that particular index of the key. Whereby the top level list is the same length as the overall key.
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
| -- The following holds true permuteAll [ [ 'a','b' ], [ 'c','d' ] ] => [ ['a','c'],['a','d'], ['b','c'], ['b','d'] ] | |
| permuteAll :: [[a]] -> [[a]] | |
| permuteAll [] = [] | |
| permuteAll (x:[]) = splitEvery 1 x | |
| permuteAll (x:xs) = foldr (++) [] $ map f x | |
| where | |
| f :: a -> [[a]] | |
| f x' = map ( \y -> (x':y) ) (permuteAll xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment