fn test_10(n: u32) -> bool { let s = n.to_string(); let sv = s.chars().collect::>(); let svr = s.chars().rev().collect::>(); for i in 0..s.len() { if sv[i] != svr[i] { return false; } } return true; } fn test_2(n: u32) -> bool { let mut sv = Vec::new(); let mut a = n; while a > 0 { sv.push(a % 2); a /= 2; } let mut svr = sv.clone(); svr.reverse(); for i in 0..sv.len() { if sv[i] != svr[i] { return false; } } return true; } fn main() { let mut sum = 0; for n in 1..1_000_000 { if test_10(n) && test_2(n) { println!("{}", n); sum += n; } } println!("{}", sum); }