Solve problem 4 using Rust.