Programming challenges (problems/puzzles/contests) are a great way to practice and sharpen programming skills. Not only are they fun, programming problems can be a good test of problem-solving skills and knowledge of computer science and mathematics. There is an abundance of online resources available for those interested in solving programming problems and participating in programming contests.
Advent of Code
In the past, I have participated in programming contests such as ACM ICPC, TopCoder, and Google Code Jam. While I still dabble in programming challenges, my interest has dwindled over time. But in December, I participated in Advent of Code (as did over twenty-five thousand folks). Little did I know, this fun programming challenge would revive my interest in programming puzzles.
Advent of Code (AoC) is the brainchild of Eric Wastl, of Vanilla JS fame. One programming puzzle was released each day of December leading up to the 25th. Daily puzzles provided participants the opportunity to make it onto the daily leaderboard. I enjoyed the varied problems and the rush of quickly solving the daily puzzle to secure a leaderboard placing.
What is a programming challenge?
A programming challenge presents a problem usually described in the form of: "Given the described conditions and rules, write code that will provide the correct output for any valid input." A simple puzzle may ask you to write a programme to find the surface area of any rectangular prism.
To help explain the problem (and to make it more enjoyable), the problem is described with some relatable context or story. For example, the aforementioned problem was described in the context of Santa's elves needing to know the amount of wrapping paper to purchase in order to wrap all the presents. References and jokes also help keep things interesting and fun.
As an answer, challenges usually require a code submission or the correct output for the provided input to be submitted. If code is submitted, the automated judging system will execute the code against a set of inputs and outputs to validate its correctness. To prevent sub-optimal (or brute force) code solutions from being judged as correct, there may be constraints on the amount of time the code can be executing.
Learning Go with Advent of Code
The programming puzzles from AoC were fairly short and were not too difficult for those familiar with programming. This made them great for learning another programming language. After solving all the puzzles in Ruby, I decided to learn Go and redo all the AoC challenges as a learning exercise.
Deliberate practice is necessary to becoming proficient. Repeating the AoC challenges in Go helped solidify my understanding of Go's syntax and concepts. As I was mostly translating my Ruby solution into Go, I could concentrate on learning Go rather than solving the programming problem.
Comparing Ruby and Go
Completing AoC again in another programming language allowed me to easily identify some differences between Go and Ruby. After completing my AoC solutions in Go, I observed:
- Go is faster than Ruby, but Go code is more verbose.
- Ruby is concise, expressive and prioritises programmer happiness.
- Ruby is easier to use with its rich API and unceremonious dynamic typing.
- Go, being a typed language with no generics, I found myself writing my own functions found in Ruby such as
- Go is a simple language to learn but perhaps more tedious to use.
More programming challenges
I had so much fun completing the AoC puzzles and I hope to see another AoC in 2016. For the moment, I am filling the gap by completing similar programming problems on other platforms. There are a lot of platforms available, some are more focused on preparing for coding job interviews than for fun and learning. Below are four programming challenge platforms that I enjoyed using.
Codewars classifies problems by their approximate difficulty and the skills they test (algorithms, logic, mathematics, regular expressions, etc.). As you rank up, Codewars will present problems appropriate to your skill level. For these reasons, Codewars is a great place to begin solving programming challenges.
Exercism.io is an open-source platform to help developers of all levels to write better code. Unlike other platforms that simply reward people for submitting a correct solution, Exercism.io values writing clean, elegant and simple code. Through feedback and discussion on the platform, developers can improve their programming skills.
As of writing, Exercism.io supports 28 different programming languages so you are bound to find a language you want to learn or master. Recently I have been using Exercism.io to sharpen my Ruby skills and to practice writing Go. My solutions so far are available on GitHub.
Project Euler combines the world of mathematics with programming problems. You will learn and sharpen your knowledge of mathematical concepts as the platform tracks your progress through the challenges. Project Euler is perfect for anyone with an interest in mathematics and programming problems.
/r/dailyprogrammer on Reddit
dailyprogrammer is a social community on Reddit. Three programming challenges of increasing difficulty are posted each week. Members submit and discuss solutions in various programming languages. There is no reward system or progress tracking and Reddit is clearly not designed to host programming challenges. Yet those familiar with Reddit will feel right at home.
I had a great time solving the daily programming puzzles from Advent of Code. It has reignited my interest in programming challenges and pushed me to learn and reacquaint myself with algorithms, data structures, and mathematical concepts. I hope to continue learning, refreshing and having fun with programming challenges.