finish 36
This commit is contained in:
@@ -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]
|
||||||
@@ -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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user