Solve #69 in scala