module Math.Combinat.Tuples where
import Math.Combinat.Helper
tuples' :: [Int] -> [[Int]]
tuples' :: [Int] -> [[Int]]
tuples' [] = [[]]
tuples' (Int
s:[Int]
ss) = [ Int
xInt -> [Int] -> [Int]
forall 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
xInt -> [Int] -> [Int]
forall 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 = [Integer] -> Integer
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product ([Integer] -> Integer) -> [Integer] -> Integer
forall a b. (a -> b) -> a -> b
$ (Int -> Integer) -> [Int] -> [Integer]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Integer
forall a a. (Integral a, Num a) => a -> a
f [Int]
shape where
f :: a -> a
f a
k = a
1 a -> a -> a
forall a. Num a => a -> 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 = [Integer] -> Integer
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product ([Integer] -> Integer) -> [Integer] -> Integer
forall a b. (a -> b) -> a -> b
$ (Int -> Integer) -> [Int] -> [Integer]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Integer
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' (Int -> Int -> [Int]
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' (Int -> Int -> [Int]
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 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Int -> Integer
forall a a. (Integral a, Num a) => a -> a
fromIntegral Int
k) Integer -> Int -> Integer
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 = Int -> Integer
forall a a. (Integral a, Num a) => a -> a
fromIntegral Int
k Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^ Int
len
binaryTuples :: Int -> [[Bool]]
binaryTuples :: Int -> [[Bool]]
binaryTuples Int
len = ([Int] -> [Bool]) -> [[Int]] -> [[Bool]]
forall a b. (a -> b) -> [a] -> [b]
map ((Int -> Bool) -> [Int] -> [Bool]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Bool
intToBool) (Int -> Int -> [[Int]]
tuples Int
len Int
1)