Solve 1-21 in scala