Solving a Puzzle Using Picat
Arrange the numbers 1-32, inclusive, in a circle such that the sum of any two adjacent numbers in the circular chain is a perfect square
References:
Arrange the numbers 1-32, inclusive, in a circle such that the sum of any two adjacent numbers in the circular chain is a perfect square
References:
This can be quite easily solved using Z3 theorem prover, once we figure out to set up the constraints.
We have 5 variables, \(\{x_i\}, i=0, 1, 2, 3, 4\) which are constrained by
where \([\cdot]\) is the Iverson Bracket notation (1 if the condition holds, 0 otherwise).
When checking the models for which the conditions are satisfied, we will also check that the number of digits satisfying the conditions holds good, using set intersection.
We solve it using python bindings to Z3, which can be installed in python virtual environment by
pip install z3-solver |
Then, we can solve the above by running the following python code:
If we remove the distinct constraint, we get 19 different solutions.
We find that Z3 and other SMT solvers are powerful tools for verification computer programs / hardware designs, perform compiler optimizations, finding bugs etc. And solving Logic puzzles!
References:
It is Tom's 7th birthday and he has a cake with seven candles on it, arranged in a circle -- but they are trick candles. If you blow on a lit candle, it will go out, but if you blow on an unlit candle, it will relight itself.
Since Tom is only 7, his aim isn't brilliant. Any time he blows on a particular candle, the two either side also get blown on as well. How can Tom blow out all the candles? What is the fewest number of puffs he can do it in?
This is a nice candidate for the shortest path problem, which can be easily solved in Sagemath as follows:
Godbolt enables us to interactively see the assembly output of the input source code by the selected compiler.
But it depends on nodejs and there's quite a delay between the modified input and the produced disassembly.
Enter RMSBolt, which is a package for emacs. It's much lighter, more powerful, and more interactive when compared to Godbolt, and perhaps the only alternative to Godbolt. Great way to learn assembly language, and fun too!