(without stringification)
fn euthanize(mut a: u64, mut b: u64) -> u64 { let mut out = 0; let mut cursor = 1; loop { let sum = a % 10 + b % 10; out += sum * cursor; cursor *= if sum < 10 { 10 } else { 100 }; a /= 10; b /= 10; if a == 0 && b == 0 { return out; } } }
fn main() { assert_eq!(euthanize(2, 11), 13); assert_eq!(euthanize(16, 18), 214); assert_eq!(euthanize(122, 81), 1103); dbg!(euthanize(1222, 30277)); dbg!(euthanize(1236, 30889)); dbg!(euthanize(49999, 49999)); }
(look at it go)
We're a place where coders share, stay up-to-date and grow their careers.
Rust
(without stringification)
// test
(look at it go)