exercise 4 from Instil's summer of code - Scala