Created
July 3, 2017 01:47
-
-
Save vitapluvia/98d8641a1ecf75d7da4c6f471318e81d to your computer and use it in GitHub Desktop.
permutations in haskell
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
import Data.List (nub) | |
disperse :: a -> [a] -> [[a]] | |
disperse value arr = | |
map (\(start, ending) -> start ++ [value] ++ ending) . | |
map (\char -> splitAt char arr) $ [0..length arr] | |
permu :: Ord a => [a] -> [[a]] | |
permu [] = [[]] | |
permu (x:xs) = concatMap (disperse x) $ permu xs | |
main = mapM_ putStrLn $ nub $ permu ['a'..'d'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment