You are viewing a single comment's thread. Return to all comments →
RUST:
fn kaprekarNumbers(p: i32, q: i32) { let mut results: Vec<String> = Vec::new(); for n in p..=q { let square = (n as u128).pow(2).to_string(); let middle = square.len() - n.to_string().len(); let (left, right) = square.split_at(middle); let left_int = left.parse::<i32>().unwrap_or(0); let right_int = right.parse::<i32>().unwrap_or(0); if left_int + right_int == n { results.push(n.to_string()); } } if results.len() > 0 { println!("{}", results.join(" ")) } else { println!("INVALID RANGE") }; }
Seems like cookies are disabled on this browser, please enable them to open this website
Modified Kaprekar Numbers
You are viewing a single comment's thread. Return to all comments →
RUST: