finish 36

This commit is contained in:
Dr. Matthias Ratajczak
2022-08-19 19:48:20 +02:00
parent 13b9f475ce
commit 6c6a58915f
2 changed files with 25 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "euler36"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+17
View File
@@ -0,0 +1,17 @@
fn main() {
let mut result = 0;
for i in 1..1_000_000 {
if is_palindrome(i.to_string().as_str()) && is_palindrome(&dec_to_bin(i)) {
result += i;
}
}
println!("{result}");
}
fn is_palindrome(s: &str) -> bool {
s.chars().zip(s.chars().rev()).all(|(a, b)| a == b)
}
fn dec_to_bin(x: u32) -> String {
format!("{:b}", x)
}