init
This commit is contained in:
6
problems/p36/Cargo.toml
Normal file
6
problems/p36/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "p36"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
28
problems/p36/src/main.rs
Normal file
28
problems/p36/src/main.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
fn is_palindromic_base10(n: u32) -> bool {
|
||||
let string = n.to_string();
|
||||
string == string.chars().rev().collect::<String>()
|
||||
}
|
||||
#[test]
|
||||
fn test_is_palindromic_base10() {
|
||||
assert!(is_palindromic_base10(585));
|
||||
}
|
||||
|
||||
fn is_palindromic_base2(n: u32) -> bool {
|
||||
if n.is_multiple_of(2) {
|
||||
return false;
|
||||
}
|
||||
let string = format!("{:b}", n);
|
||||
string == string.chars().rev().collect::<String>()
|
||||
}
|
||||
#[test]
|
||||
fn test_is_palindromic_base2() {
|
||||
assert!(is_palindromic_base2(585));
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let sum = (0..100_0000u32)
|
||||
.filter(|&x| is_palindromic_base10(x))
|
||||
.filter(|&x| is_palindromic_base2(x))
|
||||
.sum::<u32>();
|
||||
println!("sum: {sum}");
|
||||
}
|
||||
Reference in New Issue
Block a user