module Math.Combinat.Tuples where
import Math.Combinat.Helper
tuples' :: [Int] -> [[Int]]
tuples' :: [Int] -> [[Int]]
tuples' [] = [[]]
tuples' (Int
s:[Int]
ss) = [ Int
xforall a. a -> [a] -> [a]
:[Int]
xs | Int
x <- [Int
0..Int
s] , [Int]
xs <- [Int] -> [[Int]]
tuples' [Int]
ss ]
tuples1' :: [Int] -> [[Int]]
tuples1' :: [Int] -> [[Int]]
tuples1' [] = [[]]
tuples1' (Int
s:[Int]
ss) = [ Int
xforall a. a -> [a] -> [a]
:[Int]
xs | Int
x <- [Int
1..Int
s] , [Int]
xs <- [Int] -> [[Int]]
tuples1' [Int]
ss ]
countTuples' :: [Int] -> Integer
countTuples' :: [Int] -> Integer
countTuples' [Int]
shape = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall {a} {a}. (Integral a, Num a) => a -> a
f [Int]
shape where
f :: a -> a
f a
k = a
1 forall a. Num a => a -> a -> a
+ forall {a} {a}. (Integral a, Num a) => a -> a
fromIntegral a
k
countTuples1' :: [Int] -> Integer
countTuples1' :: [Int] -> Integer
countTuples1' [Int]
shape = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall {a} {a}. (Integral a, Num a) => a -> a
fromIntegral [Int]
shape
tuples
:: Int
-> Int
-> [[Int]]
tuples :: Int -> Int -> [[Int]]
tuples Int
len Int
k = [Int] -> [[Int]]
tuples' (forall a. Int -> a -> [a]
replicate Int
len Int
k)
tuples1
:: Int
-> Int
-> [[Int]]
tuples1 :: Int -> Int -> [[Int]]
tuples1 Int
len Int
k = [Int] -> [[Int]]
tuples1' (forall a. Int -> a -> [a]
replicate Int
len Int
k)
countTuples :: Int -> Int -> Integer
countTuples :: Int -> Int -> Integer
countTuples Int
len Int
k = (Integer
1 forall a. Num a => a -> a -> a
+ forall {a} {a}. (Integral a, Num a) => a -> a
fromIntegral Int
k) forall a b. (Num a, Integral b) => a -> b -> a
^ Int
len
countTuples1 :: Int -> Int -> Integer
countTuples1 :: Int -> Int -> Integer
countTuples1 Int
len Int
k = forall {a} {a}. (Integral a, Num a) => a -> a
fromIntegral Int
k forall a b. (Num a, Integral b) => a -> b -> a
^ Int
len
binaryTuples :: Int -> [[Bool]]
binaryTuples :: Int -> [[Bool]]
binaryTuples Int
len = forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> [a] -> [b]
map Int -> Bool
intToBool) (Int -> Int -> [[Int]]
tuples Int
len Int
1)