After having solved many programming puzzles, have you ever thought about creating your own puzzle? You’re not sure where to start? Or do you think you’re not up to the task?
Here are 5 easy steps that should help you create your own coding challenge.
Pick a Theme
Remember that you create a puzzle for other developers to solve it.
We developers solve puzzles for several reasons, one of them being entertainment. I think that as a creator, your first job is to entertain the solver. The theme won’t make it all but without it, you surely won’t have a great puzzle. Preferably choose a theme you like. It will be easier to create a top-notch contribution.
Now that you have a theme, you can find a puzzle idea more easily, or adapt the idea you already had to the theme.
Ex: I’m fond of tennis, the goal of my puzzle will be to compute a tennis score from the chronological list of points.
You should also think about the originality of your puzzle/theme. Try to avoid classic topics of programming puzzles (for example, Ascii Art). I advise you to check what has already been created on the platform by other members of the community.
For a Clash of Code contribution, the theme is less important. The brevity and clarity of the statement are key.
Write Tests
You’ve got the idea; there should be a goal and some rules to achieve it. Make sure to define clear rules. The solvers won’t enjoy the challenge if they don’t understand it.
How do you check that a code has solved your problem? If it passes the tests you’ve created for it.
Simply write all the conditions a solution should respect to be valid and make a test for each one of them*.
Ex: My tests should verify that a solution correctly computes the score of a game and set, handles deuce and tie break…
If it’s a scaling problem, you’ll have to write tests of simple scenarios and at least one test for a larger scenario, so a brute force solution would fail this test (ie timeout).
Write the Solution
This part helps you assess the difficulty of your problem. A too hard puzzle might deter some developers from solving it.
On the other hand, a too simple puzzle won’t be challenging for advanced developers. You can tweak the rules (and obviously modify the corresponding tests and validators) to modify the difficulty.
Even if you know the solution to your puzzle**, it might be a good idea to check on the internet for similar problems. Maybe you’ve missed a trivial solution or forgotten a specific test case.
Ex: I found a StackExchange topic about my problem which makes me realize my puzzle may be too simple. To make it more tricky, I could decide to add incomplete inputs…
Present the Challenge
This could be a boring part but this is highly important. The problem/puzzle might be familiar to you, but developers will just discover it.
A complete statement usually contains a small story, the description of the problem (goal and rules), the description of the inputs and expected output along with an example. All of it must be very clear and simple to understand, else developers might not even try to solve it. The story shouldn’t be too long. It is used to create a fun atmosphere around the programming puzzle.
The title is also important, make it sexy! However, it should not misleading.
Ex: Instead of “tennis scoring system”, I could call the puzzle “Game, Set & Match”. To be sure the description is clear, I would choose wordings from the related Wikipedia article.
Ask the Community for Review
You could think your job is finished at this step. It is not. You need to have someone review your coding challenge. Don’t explain anything about your puzzle, just give to your reviewers the puzzle and ask them to solve it.
There will be remarks for sure. Or proposals for better wording. Maybe you made a typo. Or even a mistake in the test cases.
In any case, the quality of your contribution can just increase after this process.
The tennis puzzle is obviously incomplete but you can still give your opinion on it. If the global feedback is positive, I might even take the time to really create the puzzle 🙂
If you’ve followed these 5 steps thoroughly, you’re ready to share your puzzle with the world and become famous. This is what happened to SamSi whose puzzle “Heart of the City” got featured as Puzzle of the Week.
(Careful, if you have not solved his puzzle yet, there are spoilers below)
“My college is in a military area, so we have sort of pine trees all over. My friend and I were just roaming around. I was wondering if there existed any sort of pattern as to how many trees are visible if we are surrounded by them and they have equal spacing.
At first, I thought that there was a pattern to it, I derived an equation from it and checked it against my bruteforce solution. It failed.
Later on, I realized that this problem is nothing but counting the number of co-prime pairs so I tried to find some related algorithms and I discovered Euler totient theorem.
So I decided to create a puzzle. I did several mistakes but my friend and the CodinGame community (MadKnight, Kyran…) were very helpful and told me what could be improved.
My piece of advice for creating a nice puzzle would be the following:
- it should be easy to understand
- it should be challenging
- it’s better if it’s related to nature or things people are familiar with”
Thank you SamSi and congratulations for your puzzle!