homework for MOOC programming principles in scala