Skip to content

Instantly share code, notes, and snippets.

@craigjbass
Last active December 26, 2015 17:09
Show Gist options
  • Select an option

  • Save craigjbass/7185255 to your computer and use it in GitHub Desktop.

Select an option

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.
-- 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