Created
March 3, 2017 16:14
-
-
Save xiaohanyu/44048f5ecf03016fdf468b956c6dfc6a to your computer and use it in GitHub Desktop.
Haskell permutation generation algorithm with list comprehension.
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 Data.List | |
perm :: (Eq a) => [a] -> Int -> [[a]] | |
perm _ 0 = [[]] | |
perm xs r | length xs < r = [[]] | |
| otherwise = [x:ys | x <- xs, ys <- perm (delete x xs) (r - 1)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!