Euler Coding Challenges

Seattle.rb has had a second Euler coding challenge now and the third is currently underway. I think they’ve been a successful way of getting more folks to write code. I especially like that we can include both the beginners and the experts and that the contest is self limiting so the same person doesn’t win month after month.

Standard Rules

  • Contest runs from May 7th 12:00 PM - June 3rd 12:00 PM
  • Winner is the person who completes the most Project Euler problems during the contest period.
  • Solutions may be in any language or a mix of language.
  • The solution for each problem must take less than a minute.
  • All code must be your own work. You can ask questions or discuss with other people but don’t copy code from the internet or have other people give you code at meetups.
  • There are two divisions:
    • Novice (< 1 year programming)
    • Open (everyone, including novices)
  • The winner in each division will receive $50 of my money.
  • If less than 10 people participate no prizes will be given.
  • You must be in the Seattle area to claim your prize.

How the code works

The first time I did most of the work manually. Now I’ve got the majority of the process automated via a set of mechanize scripts available on github.

Sign-up happens via a Google Form. I export the Google form in csv. update_friends.rb uses the sign up csv to set my Euler friends to the folks participating in that month’s challenge.

At the start of the challenge (typically 24 to 72 hours after announcing it) I take a first snapshot of the data using get_records.rb. This writes the current number of problems completed for each participant to records.csv. Once the contest starts I have this running on an hourly cron so that I get at least one daily snapshot. I can also use the interim snapshots to draw graphs of how many problems were completed as the challenge went along.

At any point I can see the current scores by running calculate_scores.csv. This calculates each participants score (current_num_complete - starting_num_complete). It then groups the participants by division, sorts the results of each division, and writes the score info to a file.

What I’ve learned

Project Euler has a wide range of difficulty. The first 10 or so problems are pretty easy. Using Ruby 1.9 and higher (with the Prime class) naive algorithms can complete those problems with a run time less than a minute.

Problems numbered 50 or higher are significantly more difficult. Solving these problems requires finding some trick or having a good understanding of number theory to figure out. CS fundamentals like caching, p vs np, and dynamic programming come in handy as well. After the first 75ish the problems get hard enough that the $50 prize isn’t enough to motivate folks to keep plugging away. As a result the same people aren’t winning every month and folks who’ve never participated before are most likely to win.

The Project Euler problems are very mathy and use a lot of technical math vocabulary. Many of the underlying concepts are grade school math (primes, palindromes, Fibonacci, triangle numbers) but the way the problems are described has been intimidating to some folks.

I’ve found that many common whiteboard interview questions are similar to Project Euler problems. I know a couple Seattle.rb attendees who have used our challenges as incentive to practice this style of questions. I hope that has helped them do well on interviews. I know it has helped me.

Finally, I’ve learned that people get competitive and want to see their relative ranks. I want more overall participation and so in the past I’ve chosen not share scores very often. This was especially true in the first challenge when one participant had 4x the score of the next nearest person. I was concerned that seeing that one individual was so far ahead would discourage others from participating at all.

This time around I’ve been sharing the scores weekly to see how it changes things. I’ve been getting more corrections and questions about how the scoring works this time (hence this blog post). I don’t think seeing the scores has discouraged any one from participating but it is probably too early to tell.

What I want to do in the future

I’d like to find a less mathy but similar set of problems to do for a future challenge. Ideally it would be something that has graduated difficulty, has automated grading/scoring, is easy for me to get participants scores, each problem can be done independently, and doesn’t take more than a few hours. is likely to be used for a future challenge. I’d also love to do something like the multi-player challenges from Code Combat. We’ll see what makes it easy enough that I can run a challenge in less than an hour a week.