About a year ago, there was a hot topic in the internet about the difficulty of a primary one student homework in Hong Kong. Below is an example of primary one student homework. This is a cryptarithm problem, where each character represents a unique number from 0 to 9, and you are asked to come up with the value of each character without any aid of computer.

Cryptarithm for Primary one students in Hong Kong

This may sound very easy for some of you but may not for a primary one student. Although from the home work title ‘Math Challenge’, I guess it may not be not be a marked homework, it raised some concerned. At some point, the focus of discussion suddenly shifted to ‘How to write a good program’.

The starting point is: one of the parents wrote a brute-force solution and post it to the forum. All of sudden, people start to have a seriously discussion on scalability and efficiency of the program. Some of the coders start to come up with their ‘best’ solution in various languages.

Brute force solution written by internet user

In my opinion, despite the fact that doing these questions without programming can train student’s spatial intelligence, in practical situation, neither solving with your own algorithm or without any program is time-efficient when the problem comes to a large scale.

Thanks to Coursera and the University of Melbourne, I recently came across the Modeling Discrete Optimization course (Update: There is now a new course co-taught by the University of Melbourne and the Chinese University of Hong Kong!) which teaches a constraint modeling language called MiniZinc, which allowed us to communicate with constraint solvers written by hundreds of researchers to solve our problem.

Find a solution for the problem using MiniZinc

With Minizinc, we can just a few lines of code and get a solution in 46 ms. Isn’t it amazing?! (comparing to writing a brute force solution :] ) Minizinc also supports the function of getting all feasible solutions and given a objective function to optimized towards, for example if you want to minimize the sum of all character value.

I strongly recommend students to take the coursera course and learn MiniZinc . First of all, converting a question into a model is an important skill set which is often used in Mathematics. Secondly, you barely can write a better algorithm to solve the problem efficiently unless intensely trained in the field. Lastly, modeling language is more human readable and interpretable than other programming language.

So, Let’s get started!

See: MiniZinc code for the cryptarithm solution.