one basic solution to problem 1
Minor modification