scala exercises (attempted P27a)