Last active
May 17, 2018 19:05
-
-
Save varreli/13eb5adcddc52ae87847156389b0f5e1 to your computer and use it in GitHub Desktop.
variation of function choices
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 Debug.Trace | |
subs :: [a] -> [[a]] | |
subs [] = [[]] | |
subs (x:xs) = yss ++ map (x:) yss | |
where yss = subs xs | |
interleave :: a -> [a] -> [[a]] | |
interleave x [] = [[x]] | |
interleave x (y:ys) = (x:y:ys) : map (y:) (interleave x ys) | |
perms :: [a] -> [[a]] | |
perms [] = [[]] | |
perms (x:xs) = trace "now it terminates" concat (map (interleave x) (perms xs)) | |
choices :: [a] -> [[a]] | |
choices = concat . map perms . subs | |
choices' :: [a] -> [[a]] | |
choices' xs = [ list | yss <- subs xs, | |
list <- perms yss ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment