Refactor Rust's problem 53.