solution for 3-6.cpp

My solution probably worked, but was not optimal.
Merge pull request #15 from PollockCR/solution

solution for 3-6.cpp