Sha256: f367f231ea2001e134f3c1b95af7868b11c8a05e3608eb5d77c0de325b6cca8c
Contents?: true
Size: 478 Bytes
Versions: 77
Compression:
Stored size: 478 Bytes
Contents
pub fn classify(num: u64) -> Result<Classification, & 'static str> { if num == 0 { return Err("Number must be positive"); } let sum: u64 = (1..num).filter(|i| num%i == 0).sum(); if sum == num { Ok(Classification::Perfect) } else if sum < num { Ok(Classification::Deficient) } else { Ok(Classification::Abundant) } } #[derive(Debug, PartialEq, Eq)] pub enum Classification { Abundant, Perfect, Deficient }
Version data entries
77 entries across 77 versions & 1 rubygems