/code/blog

Code, code and code

Learning Functional Programming Through Project Euler

ProjectEuler is a wonderful project which provides a number of problems to be solved by writing code. I happened to be attempting to enhance my skills at writing more functional programming oriented code. One of the pages I ran into suggested using the ProjectEuler problems as a way to build and exercise ability to write code using functional programming constructs.

As I started solving these exercises, I realised I probably had the most useful set of problems that would help me build the skill I wanted to. The language of choice for the solutions is python. However python does allow you to write using multiple paradigms - traditional structured, object oriented or even functional. Since I was familiar with the first two and wanting to build capability in the last, it took a great degree of effort to early on write solutions using functional constructs (and eschewing object oriented solutions that I am so comfortable with).

I have found these exercises most helfpul and am sharing my experiences and solutions in the hope that the readers may benefit from some of these and that we can have an intelligent conversation around some of the solutions and their appropriateness in the comment stream. I am not an expert in functional programming, so am more than willing to stand corrected. Just drop a note in the comments and I shall learn from your opinions and thoughts as well, and may even modify some of the solutions should it seem necessary.

Note that project euler problems are not specific to either functional programming or python. They are just as useful to alternative programming styles or other programmiing languages. Functional constructs using python is merely my implementation choice for solving these problems.

This post and all the subsequent solutions can be reviewed by following the tag projecteuler

Comments