Another more elegant and short way of doing problem 5
Problem 7