Created
November 1, 2012 03:48
-
-
Save weskerfoot/3991563 to your computer and use it in GitHub Desktop.
Haskell - permutations
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 Control.Monad | |
enumerate xs = zip [1..] xs | |
dlists :: [a] -> [(a, [a])] | |
dlists xs = [(x, [y | (j, y) <- enumerate xs, j /= i]) | (i, x) <- enumerate xs] | |
permute (x:y:[]) = [y:x:[], x:y:[]] | |
permute xs = let difflist = dlists xs | |
in join [map (i:) (permute d) | (i, d) <- difflist] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment