Solution to part 4 of exercise 1