From 8dd228e5a94d9fbcc9409773279b38ee13eb791d Mon Sep 17 00:00:00 2001 From: Coin de Gamma <cg@corpglory.com> Date: Mon, 27 Feb 2023 09:42:18 +0000 Subject: [PATCH] 004 ok --- 004/solution.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 004/solution.rs diff --git a/004/solution.rs b/004/solution.rs new file mode 100644 index 0000000..0bf1eb4 --- /dev/null +++ b/004/solution.rs @@ -0,0 +1,43 @@ +//use std::iter::zip; + +fn is_polindrome(n: i32) -> bool { + let s = n.to_string(); + for (p, q) in s.chars().zip(s.chars().rev()) { + // println!("-{}-{}-", p, q); + if q != p { return false; } + } + return true; +} + +fn main() { + + //let nnnn = 999 * 999 * 999; + //let m_nnn = u32::MAX; + //println!("{} vs {}", nnnn, m_nnn); + let n = 999; + + //let mut i = n; + //let mut j = n; + //let mut k = n; + + let mut best_i = 1; + let mut best_j = 1; + + let mut best_poli = 1; + + for i in 100..=n { + for j in 100..=n { + let m = i * j; + if is_polindrome(m) { + if m > best_poli { + best_poli = m; + best_i = i; + best_j = j; + } + } + } + } + println!("{}*{}={}", best_i, best_j, best_poli); + //let p = is_polindrome(999 * 999 * 999); + //println!("{}", p); +}