initial working solution to problem 3
iteration 2 of problem 3. Cleaner, but benchmark is roughly equivilient to iteration 1.