Chinese Remainder: Avoid map/zip/map courtesy of mamad :3
This commit is contained in:
@@ -46,11 +46,9 @@ pub fn chinese_remainder(residues: &[i64], moduli: &[i64]) -> Option<i64> {
|
||||
// TODO: Filter out 0s in moduli (meaning big_n is 0 -> div by 0)
|
||||
let big_n: i64 = moduli.iter().product();
|
||||
Some(moduli.iter()
|
||||
.map(|&ni| {
|
||||
egcd(ni, big_n / ni)
|
||||
})
|
||||
.zip(residues)
|
||||
.map(|(egcd,ai)| {
|
||||
.map(|(&ni, ai)| {
|
||||
let egcd = egcd(ni, big_n / ni);
|
||||
if egcd.gcd != 1 {
|
||||
// Fail in case moduli are not co-prime
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user