DEV Community

Jen Chang
Jen Chang

Posted on • Originally published at Medium on

Google Code Jam to I/O Mental Preparation

This is the first year that I will be attempting the Code Jam to I/O for women programming contest. Google hosts an annual code jam challenge and this is the fifth year that they are targeting towards women specifically to help increase diversity in the online contest space and representation at the Google I/O developer’s conference. The easiest part was the registration and deciding what language I will be using during the contest. For reference, you can view the solutions and other statistics including the most popular languages used for submission in the past years. You are allowed to use any programming language (including those not on the registration list). The hardest part comes next, which is getting myself mentally ready for the challenge and what follows are the things I am doing to prepare myself.

Preparation

For preparation, I am reviewing problems from the past years. I study some of the solutions to see what libraries the developers used and how they parsed the input. I am imaging that these should be the same regardless of the problem set. I was also debating whether to use python or swift. I am familiar with swift and use it frequently at work but most recently I have been learning python, which is among the top programming languages used and very powerful for manipulating large dataset. Anyhow, I did not want to spend much time on deciding so I went with some performance benchmarks, and I tried my hands at some sample challenges to familiarize myself with the process so I could potentially compete more successfully.

Tools

I created a new Command Line Project in Xcode and reused it to tackle each sample challenge set. You need a main.swift file for the command line project so I made separate folders to contain the problem solution and sample input files. My folder structure look like this:

Notice that each exercise has their own main.swift and ParseInput.swift files. I only include one main.swift file in the actual Xcode project for the current problem I’m tackling so that Xcode doesn’t get confused. Parsing the content of the input files will probably be very similar for each of the challenge, so all the reusable reading methods are found in the ParseInput.swift file. As part of the submission process, I chose to read the content of the sample files via standard input. Therefore, I created a small shell script to compile/re-run my solution as often and as quickly as possible.

My shell script looks like this:

To run the script, you will pass the problem number and the name of the sample input without the file extension. Here is an example:

./re-run-code-jam.sh 2 B-small-practice

If you are curious about how I parsed the lines via standard input using generics, take a look below:

During the Contest

These are the steps I will be taking to tackle each problem during the contest when the time comes:

  1. Spend some time to understand the problem. The problem tends to be very wordy but it gives you all the information you need. I often have to read the problem description couple of times before coding my solution. Understanding the problem correctly will save you a lot of time later.
  2. Come up with an approach to solve the problem on paper, test it against the sample input and compare your solution.
  3. Code up the solution if you think you got it.
  4. Test out your solution with a small subset of the problem and fix any obvious bugs in Xcode. I included extra print statements to ensure the content is read/or computed correctly.
  5. Download the small and large sample files to generate your expected output. Repeat the last step as needed.
  6. Do any last minute clean up and submit your output and source code!

Wish me luck! If you are also participating, good luck, too! Let’s have some fun. :)

Top comments (0)