Skip to content

Instantly share code, notes, and snippets.

@thetyrelcorporation
Created October 24, 2015 18:58
Show Gist options
  • Save thetyrelcorporation/4587a7d1b34d1b569eb3 to your computer and use it in GitHub Desktop.
Save thetyrelcorporation/4587a7d1b34d1b569eb3 to your computer and use it in GitHub Desktop.
My first math lib
extern crate num;
use self::num::traits::{Num, Zero, One, Signed, Unsigned, Bounded, Saturating, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv, PrimInt, Float, ToPrimitive, FromPrimitive, NumCast}
pub fn number_of_factors<T: Num + Zero + One + Signed + Unsigned + Bounded + Saturating + CheckedAdd + CheckedSub + CheckedMul + CheckedDiv + PrimInt + Float + ToPrimitive + FromP
let one = 1 as T;
let zero = 0 as T;
let mut factor_count: T = one;
let mut limit = n;
let mut i: T = one;
while i < limit {
if n % i == zero {
limit = n / i;
if limit != i {
factor_count = factor_count + one;
}
factor_count = factor_count + one;
}
i = i + one;
}
factor_count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment