Solve exercises for chapter #2

Answers for chapter #2 with all tests passing.