solving exercise 10 from text-files