Haskell: Create unique n-tuples from a list of x elements -


i have list of x elements have possible unique n-tuples.

so looking implementation of

nub . map (take n) . permutations 

that doesn't unnecessarily create duplicates.

for me, looks function has chance of being defined somewhere.

is case?

do mean this?

import data.list (permutations)  choose n list = concatmap permutations $ choose' list []   choose' []     r = if length r == n [r] else []   choose' (x:xs) r | length r == n = [r]                    | otherwise     = choose' xs (x:r)                                    ++ choose' xs r 

output:

*main> choose 2 [0..5] [[1,0],[0,1],[2,0],[0,2],[3,0],[0,3],[4,0],[0,4],[5,0],[0,5],[2,1] ,[1,2],[3,1],[1,3],[4,1],[1,4],[5,1],[1,5],[3,2],[2,3],[4,2],[2,4] ,[5,2],[2,5],[4,3],[3,4],[5,3],[3,5],[5,4],[4,5]] 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -