advent2021-0.1.0.0: Advent of Code 2021 Solutions
Copyright2021 Eric Mertens 2011 Daniel Fischer 2016-2017 Andrew Lelechenko Carter Schonwald Google Inc.
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Advent.Chinese

Description

Synopsis

Documentation

data Mod Source #

A package of a residue and modulus. To toMod when constructing to ensure the reduced invariant is maintained.

Constructors

Mod 

Fields

Instances

Instances details
Eq Mod Source # 
Instance details

Defined in Advent.Chinese

Methods

(==) :: Mod -> Mod -> Bool #

(/=) :: Mod -> Mod -> Bool #

Read Mod Source # 
Instance details

Defined in Advent.Chinese

Show Mod Source # 
Instance details

Defined in Advent.Chinese

Methods

showsPrec :: Int -> Mod -> ShowS #

show :: Mod -> String #

showList :: [Mod] -> ShowS #

toMod Source #

Arguments

:: Integer

integer

-> Integer

modulus

-> Mod

residue mod modulus

Construct an element of Mod with a given value and modulus. Modulus must be greater than zero.

chinese :: [Mod] -> Maybe Integer Source #

Find an integer that is equal to all the given numbers individually considering the modulus of those numbers.

Example: If x = 2 (mod 3) = 3 (mod 5) = 2 (mod 7) then x = 23

>>> chinese [toMod 2 3, toMod 3 5, toMod 2 7]
Just 23