oily-solutions/largest_palindrome_product.rs

17 lines
408 B
Rust
Raw Permalink Normal View History

2024-11-20 08:36:13 +00:00
fn main() {
2024-11-20 20:44:03 +00:00
let mut product: i64 = 0;
2024-11-20 08:36:13 +00:00
for i in 1..=999 {
for j in 1..=999 {
2024-11-20 20:44:03 +00:00
let product_string: String = format!("{:?}", i * j);
2024-11-20 08:36:13 +00:00
let reversed_string = product_string.chars().rev().collect::<String>();
2024-11-20 20:44:03 +00:00
if i * j > product && reversed_string == product_string {
product = i * j;
2024-11-20 08:36:13 +00:00
}
}
}
2024-11-20 20:44:03 +00:00
2024-11-20 08:36:13 +00:00
println!("{}", product);
}