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.139 | tracks/rust/exercises/palindrome-products/example.rs |
trackler-2.2.1.138 | tracks/rust/exercises/palindrome-products/example.rs |