Using JavaScript in Google Code Jam

Today I participated in Code Jam’s second round; I didn’t do very well, but it was definitely an entertaining experience.

To compete in Code Jam, I use JavaScript; not a lot of people use it, and even less do well in the competition. Still, the statistics show a large increase of contestants using it compared to the last year.

As I mentioned in my previous post, multi-dimensional arrays are quite useful to solve algorithmic problems, but it’s not the only thing I’ve used; I also created a mini-development environment to code the solution, and I decided to release it as an open source project.

This is not the first project of this kind; I found some alternatives here and here, but my version has the following advantages:

  • Helper functions to read the input with ease.
  • Support for file drag & drop for the input, and also an automatic “big file mode” for files too large to be placed inside a text field.
  • Integrated Big Integer library; it comes with Tom Wu’s BigInt library, which is really handy to solve problems with very large numbers, which aren’t infrequent in Code Jam.
  • Includes a “runner” web page that contains a simplified version of the IDE in a single file, so it’s easy to send along with the coded solution.
  • Uses web workers to run the code in a separate thread, and local storage to remember the last data.

It’s compatible with at least Firefox and Chrome (the runner page should run in almost any browser). This tool has helped me achieve better scores in Code Jam, so I hope it can help you too!

comments powered by Disqus