Skip to content

Commit

Permalink
Eliminate unnecessary abs() in pollards_rho
Browse files Browse the repository at this point in the history
  • Loading branch information
hesampakdaman committed Apr 7, 2024
1 parent 8b02f17 commit 05e52e6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/algorithms/pollards_rho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ use crate::traits::Factorize;
use crate::PrimeFactorization;
use num_bigint::BigInt;
use num_integer::Integer;
use num_traits::{One, Signed};

pub struct PollardsRho;

impl Factorize for PollardsRho {
fn factorize(n: &BigInt) -> BigInt {
let init = BigInt::from(2);
let psudorandom_fn = utils::generate_pseudorandom_fn(n);
let finished = move |x: &BigInt, y: &BigInt| (x - y).abs().gcd(n) != BigInt::one();
let finished = move |x: &BigInt, y: &BigInt| (x - y).gcd(n) != BigInt::from(1);
let (tortoise, hare) = utils::floyds_cycle_detection(init, &psudorandom_fn, &finished);
(hare - tortoise).abs().gcd(n)
(hare - tortoise).gcd(n)
}
}

Expand Down

0 comments on commit 05e52e6

Please sign in to comment.