Refactor Rust's problem 19.