Spark solution for chapter 3