module Data.Rhythm.Partitions
( partitions,
partitionsAllowed,
partitionsLength,
partitionsLengthAllowed,
)
where
import Math.Combinat.Partitions (Partition, fromPartition, partitionsWithKParts)
import Math.Combinat.Partitions qualified as Partitions
partitions :: Int -> [Partition]
partitions :: Int -> [Partition]
partitions = Int -> [Partition]
Partitions.partitions
partitionsAllowed :: (Foldable t) => t Int -> Int -> [Partition]
partitionsAllowed :: forall (t :: * -> *). Foldable t => t Int -> Int -> [Partition]
partitionsAllowed t Int
allowed Int
n =
(Partition -> Bool) -> [Partition] -> [Partition]
forall a. (a -> Bool) -> [a] -> [a]
filter ((Int -> Bool) -> [Int] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Int -> t Int -> Bool
forall a. Eq a => a -> t a -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` t Int
allowed) ([Int] -> Bool) -> (Partition -> [Int]) -> Partition -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Partition -> [Int]
fromPartition) (Int -> [Partition]
partitions Int
n)
partitionsLength :: Int -> Int -> [Partition]
partitionsLength :: Int -> Int -> [Partition]
partitionsLength = Int -> Int -> [Partition]
partitionsWithKParts
partitionsLengthAllowed :: (Foldable t) => Int -> t Int -> Int -> [Partition]
partitionsLengthAllowed :: forall (t :: * -> *).
Foldable t =>
Int -> t Int -> Int -> [Partition]
partitionsLengthAllowed Int
len t Int
allowed =
(Partition -> Bool) -> [Partition] -> [Partition]
forall a. (a -> Bool) -> [a] -> [a]
filter ((Int -> Bool) -> [Int] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Int -> t Int -> Bool
forall a. Eq a => a -> t a -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` t Int
allowed) ([Int] -> Bool) -> (Partition -> [Int]) -> Partition -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Partition -> [Int]
fromPartition) ([Partition] -> [Partition])
-> (Int -> [Partition]) -> Int -> [Partition]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> [Partition]
partitionsLength Int
len