module Ersatz.Counting where

import Ersatz.Bit
import Ersatz.Bits
import Ersatz.Codec
import Ersatz.Equatable
import Ersatz.Orderable

exactly :: Int -> [ Bit ] -> Bit
exactly :: Int -> [Bit] -> Bit
exactly Int
k [Bit]
bs = Decoded Bits -> Bits
forall a. Codec a => Decoded a -> a
encode (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
k) Bits -> Bits -> Bit
forall t. Equatable t => t -> t -> Bit
=== [Bit] -> Bits
forall (t :: * -> *). Foldable t => t Bit -> Bits
sumBit [Bit]
bs

atmost :: Int -> [ Bit ] -> Bit
atmost :: Int -> [Bit] -> Bit
atmost Int
k [Bit]
bs = Decoded Bits -> Bits
forall a. Codec a => Decoded a -> a
encode (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
k) Bits -> Bits -> Bit
forall t. Orderable t => t -> t -> Bit
>=? [Bit] -> Bits
forall (t :: * -> *) a. (Foldable t, HasBits a) => t a -> Bits
sumBits [Bit]
bs

atleast :: Int -> [ Bit ] -> Bit
atleast :: Int -> [Bit] -> Bit
atleast Int
k [Bit]
bs = Decoded Bits -> Bits
forall a. Codec a => Decoded a -> a
encode (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
k) Bits -> Bits -> Bit
forall t. Orderable t => t -> t -> Bit
<=? [Bit] -> Bits
forall (t :: * -> *) a. (Foldable t, HasBits a) => t a -> Bits
sumBits [Bit]
bs