scala exercises (P59) attempt