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

Version Path
trackler-2.2.1.110 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.109 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.108 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.107 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.106 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.105 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.104 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.103 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.102 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.101 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.100 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.99 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.98 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.97 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.96 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.95 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.94 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.93 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.92 tracks/rust/exercises/perfect-numbers/example.rs
trackler-2.2.1.91 tracks/rust/exercises/perfect-numbers/example.rs