Saturday, August 10, 2013

Introduction

For almost 24 hours over a 30 hour period (I did eat and sleep), I participated in the 4th Machinis Ludo Game Jam at the graphics lab at Williams College, which in this iteration was a generalized hackathon. As my challenge for this hackathon, I decided to try to solve 20 Project Euler problems in 24 hours ... in 20 different programming languages. This ended up being a very challenging and fun exercise, as well as one that was perfectly scoped (I finished with only 4 minutes to spare).

Project Euler has a set of increasingly difficult "math" problems that are meant to be solved through code. I have done about 100 of them without constraints (I used it as a way to learn Python and Racket/Scheme, as well as just to have fun), but now I am going through, trying to use each programming language only once. Now I have done 20 problems in 20 languages, but my goal is to eventually do 30 in 30, 40 in 40, etc...

The timed version of this challenge was fun and exiting for various reasons - I got to use esoteric programming languages with a "real" purpose in mind (this was probably the only way I was going to ever write 100 lines of BrainFuck in my life), I got to begin to learn real programming languages that I had never used before at least in a rudimentary manner (I got to use Ruby, Perl, Haskell, Go, and other languages for the first time), and I got to deal with some really interesting optimality problems - such as I have 2 hours left, 6 problems left, and only 4 languages left that I actually know how to use...how do I distribute languages to the problems, etc?

Now, I am going to embark on an untimed continuation of this challenge...I will try to do as many problems in as many languages as possible. The original rules I set for myself are here, but below are my revised/amended rules for this longer version:

Restatement of old Rules:

  • For two languages to be considered "different", they must not differ only in age or by a superset/subset relation. For example, Java 1, Java 2, and Java 7 are all one language to me, and as C++ is just a superset of C, C/C++ will count as one language. The only exceptions I may make to this rule are extreme subsets - for example, C++ with only templates and the C preprocesser.
  • All solutions must output the actual solution to the problem, not just intermediary data, and all solutions will be posted both here and, if I deem it interesting enough, to the Project Euler forums. It is worth noting that it goes against Project Euler policy to spread the answers outside of Project Euler, as everyone should do the work themselves. But I feel like the point of Project Euler is to work for the solutions, so the amount of interest there may be in my code in crazy languages probably outweighs any facilitation of "cheating" on Project Euler, because why would you cheat?
  • All solutions will be written independent of Project Euler-specific help on the problems (no looking at my old code from pre-PELC solutions, etc)
New Rules:
  • "The Swap Rule": When I was timing myself, once I used a solution for a problem, that was it, that language was shut off from me and I could not use it every again, its my own fault for using J to solve problem 3 (really, that was a dumb decision...J is pretty much the best PE language, at least for problems 1-50 or so). But now I am coming to a difficult point if I continued in this manner - I want to write more solutions, and I want to use crazy languages, but the problems are getting harder, so it is very hard to use a crazy esoteric language! So, I am adding the "Swap Rule", which is that if I can rewrite my solution to an earlier problem in a different language, I can swap the two solutions, allowing me to use the older language for another problem in the future.
  • "The Analytic Solution Rule": For a few problems (you know who I am talking about...Problems 5, 8, and 15), I could easily write down a solution in the form of a few multiplications, making writing a solution in code trivial...most languages support multiplication without jumping through many hurdles. Because using a hard language in this uncreative way is unfun (I used Whenever and Fortran95 on these...but I should use those for real things), If I can analytically (that is, with pencil, paper, my brain, a few minutes, and MAYBE a four-function calculator) I can find a solution, then no program need be written for that problem, so I don't waste any language solving that problem trivially. This way, whenever I use a language, I have to USE the language.\
With these two extra rules, I am ready to proceed in my challenge...most likely I will first "clean up" my initial 20 solutions using my new 2 rules, and then proceed into the great unknown that waits beyond question 21.

2 comments:

  1. Interesting challenge, and good luck keeping it up through 2014. I've done almost 100 of the problems, but they've only been done in Java or Python, so I definitely will go back and complete them in a variety of the languages here.

    ReplyDelete
  2. Thank you so much for showing interest in this: and yeah, I have solved more problems in the past (mostly in Racket, Python, and Java), but I find this challenge to both be fun, and, well, challenging, and I am glad to see that someone else is inspired to do similarly.

    ReplyDelete