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)
|
// TODO: Filter out 0s in moduli (meaning big_n is 0 -> div by 0)
|
||||||
let big_n: i64 = moduli.iter().product();
|
let big_n: i64 = moduli.iter().product();
|
||||||
Some(moduli.iter()
|
Some(moduli.iter()
|
||||||
.map(|&ni| {
|
|
||||||
egcd(ni, big_n / ni)
|
|
||||||
})
|
|
||||||
.zip(residues)
|
.zip(residues)
|
||||||
.map(|(egcd,ai)| {
|
.map(|(&ni, ai)| {
|
||||||
|
let egcd = egcd(ni, big_n / ni);
|
||||||
if egcd.gcd != 1 {
|
if egcd.gcd != 1 {
|
||||||
// Fail in case moduli are not co-prime
|
// Fail in case moduli are not co-prime
|
||||||
None
|
None
|
||||||
|
|||||||
Reference in New Issue
Block a user