Tuesday, May 26, 2015

Solutions to a small kids puzzle

How to solve the following kid puzzle by using only digits from 1 to 9 exactly one time :

With the following code, I found 20 solutions if we take into account operators priority, 119 without.
The solutions are :
List(3, 2, 1, 5, 4, 7, 8, 9, 6)
List(3, 2, 1, 5, 4, 7, 9, 8, 6)
List(5, 2, 1, 3, 4, 7, 8, 9, 6)
List(5, 2, 1, 3, 4, 7, 9, 8, 6)
List(5, 3, 1, 7, 2, 6, 8, 9, 4)
List(5, 3, 1, 7, 2, 6, 9, 8, 4)
List(5, 4, 1, 9, 2, 7, 3, 8, 6)
List(5, 4, 1, 9, 2, 7, 8, 3, 6)
List(5, 9, 3, 6, 2, 1, 7, 8, 4)
List(5, 9, 3, 6, 2, 1, 8, 7, 4)
List(6, 3, 1, 9, 2, 5, 7, 8, 4)
List(6, 3, 1, 9, 2, 5, 8, 7, 4)
List(6, 9, 3, 5, 2, 1, 7, 8, 4)
List(6, 9, 3, 5, 2, 1, 8, 7, 4)
List(7, 3, 1, 5, 2, 6, 8, 9, 4)
List(7, 3, 1, 5, 2, 6, 9, 8, 4)
List(9, 3, 1, 6, 2, 5, 7, 8, 4)
List(9, 3, 1, 6, 2, 5, 8, 7, 4)
List(9, 4, 1, 5, 2, 7, 3, 8, 6)
List(9, 4, 1, 5, 2, 7, 8, 3, 6)