Sha256: 7081988cefbdd90382eb873b5906f1d2ef512cebc2d2d17d147e5edb394ded39

Contents?: true

Size: 698 Bytes

Versions: 42

Compression:

Stored size: 698 Bytes

Contents

pub type Palindrome = u64;
pub fn get_palindrome_products(min: u64, max: u64) -> Vec<Palindrome> {
    let mut palindromes: Vec<u64> = Vec::new();
    for i in min..max + 1 {
        for j in min..max + 1 {
            if is_palindrome(i * j) {
                palindromes.push(i * j);
            }
        }
    }
    palindromes
}

pub fn min(palindromes: &[Palindrome]) -> Option<Palindrome> {
    palindromes.iter().min().map(|n| n.clone())
}

pub fn max(palindromes: &[Palindrome]) -> Option<Palindrome> {
    palindromes.iter().max().map(|n| n.clone())
}

fn is_palindrome(n: u64) -> bool {
    let s = n.to_string().into_bytes();
    s.iter().zip(s.iter().rev()).all(|(c1, c2)| c1 == c2)
}

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.179 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.178 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.177 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.176 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.175 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.174 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.173 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.172 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.171 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.170 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.169 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.167 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.166 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.165 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.164 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.163 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.162 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.161 tracks/rust/exercises/palindrome-products/example.rs
trackler-2.2.1.160 tracks/rust/exercises/palindrome-products/example.rs