When Python 3.6 was released, I was pleased to see my last reservations about Python 3 addressed, and appealing improvements to the language, in performance as well as in features. Thus, I started making the personal switch from 2.7 to 3.6 in January, committing to using 3.6 over 2.7 whenever possible, i.e. unless dealing with some legacy system or library.
In effort to familiarize myself with Python 3.6’s new features and subtle differences to 2.7, I decided to revisit the Project Euler exercises, and to do the first fifty. I am sharing my solutions in this GitHub repository. Take a look!
In solving these problems, I noticed that particular kinds of functions are required over and over again: for example, lots of Project Euler problems require you to generate some prime numbers. I bundled all these re-usable helper functions into a small package called Utilities. This package has near-complete test coverage: I added unit tests for all included functions except one. I also included a script, confirm-solutions.py, that runs all the solutions in a batch. Between this and the test coverage, it’s very easy to detect when some changes to the helper functions break any functionality.
Though I wrote my solutions casually, I tried to use reasonably clear variable names and light comments to indicate the reasoning behind my solutions. The Project Euler exercises, as far as I’m familiar with them, are generally not so much about writing code to solve problems as they are about finding theoretically efficient ways to solve problems, and then implementing them in practice. If you’re working on the problems yourself, I hope that you may find my solutions useful.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.