scala solutions of chapter 4