Solution to J&M exercise 4