Chinese Remainder: Avoid map/zip/map courtesy of mamad :3

This commit is contained in:
2021-02-08 18:55:40 +11:00
parent 15d9bb216a
commit fc8d16b6b8

View File

@@ -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