1
0
This commit is contained in:
2026-02-04 11:15:03 +08:00
commit 8b20a5dd21
125 changed files with 4177 additions and 0 deletions

6
problems/p36/Cargo.toml Normal file
View File

@@ -0,0 +1,6 @@
[package]
name = "p36"
version = "0.1.0"
edition = "2024"
[dependencies]

28
problems/p36/src/main.rs Normal file
View 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}");
}