solved 5, 6, 9 in scala