Started working on solution for p31 using recursive algorithm