Message Boards Message Boards

22
|
18414 Views
|
2 Replies
|
27 Total Likes
View groups...
Share
Share this post:

Solving computationally the "True Genius: Grecian Computer" puzzle

Disclaimer: I'm not a mathematician. I'm merely a hobbyist that loves programming and puzzles. Professionally, I work in IT management.

For my birthday this year, my young nephew (much aware of my love for puzzles) gifted me a wooden brainteaser called "Grecian Computer" from the brand True Genius.

enter image description here

As described on the box, the goal is to "Turn the dials until all 12 columns add up to 42." Rather than faffing about with trial and error, I figured it would be much more fun and educational to try my hand at writing a bit of Wolfram Language code to produce the solution.

My first step was to disassemble the puzzle to understand its structure: five "dials", the bottom of which remains fixed in place while the remaining four may rotate through twelve positions. Each dial effectively contains a 4x12 matrix comprised of numbers and "holes" where numbers from lower dials may show through. enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Using the Wolfram Language's functions for handling lists of lists, the puzzle seems readily represented as a three dimensional array: five layers, each with four rows of twelve columns. Here, I represent "holes" as zeroes:

puzzle = {{{8, 3, 4, 12, 2, 5, 10, 7, 16, 8, 7, 8}, {4, 4, 6, 6, 3, 3,
      14, 14, 21, 21, 9, 9}, {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 
     15}, {11, 11, 14, 11, 14, 11, 14, 14, 11, 14, 11, 14}}, {{1, 0, 
     9, 0, 12, 0, 6, 0, 10, 0, 10, 0}, {3, 26, 6, 0, 2, 13, 9, 0, 17, 
     19, 3, 12}, {9, 20, 12, 3, 6, 0, 14, 12, 3, 8, 9, 0}, {7, 0, 9, 
     0, 7, 14, 11, 0, 8, 0, 16, 2}}, {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
     0, 0}, {22, 0, 16, 0, 9, 0, 5, 0, 10, 0, 8, 0}, {11, 26, 14, 1, 
     12, 0, 21, 6, 15, 4, 9, 18}, {17, 4, 5, 0, 7, 8, 9, 13, 9, 7, 13,
      21}}, {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 
     0, 0, 0, 0, 0, 0}, {14, 0, 9, 0, 12, 0, 4, 0, 7, 15, 0, 0}, {11, 
     6, 11, 0, 6, 17, 7, 3, 0, 6, 0, 11}}, {{0, 0, 0, 0, 0, 0, 0, 0, 
     0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 
     0, 0, 0, 0, 0, 0, 0, 0}, {7, 0, 15, 0, 8, 0, 3, 0, 6, 0, 10, 
     0}}};

Next, we need to create a table of all of the possible permutations, rotating each of the four moving dials through its twelve possible positions, like a clock. I calculated there should be 20,736 possible permutations: 1x12x12x12x12:

puzzlePermutations = 
  Flatten[
   Table[{puzzle[[1]], RotateRight[puzzle[[2]], {0, a}], 
     RotateRight[puzzle[[3]], {0, b}], 
     RotateRight[puzzle[[4]], {0, c}], 
     RotateRight[puzzle[[5]], {0, d}]}, {a, 0, 11}, {b, 0, 11}, {c, 0,
      11}, {d, 0, 11}], 3];

Length[puzzlePermutations]

The next step was to "lift" the numbers from the lower dials to fill in the "holes" represented as zeroes:

Do[puzzlePermutations[[x]][[i]] = 
   ReplacePart[puzzlePermutations[[x]][[i]], 
    AssociationThread[
     Position[puzzlePermutations[[x]][[i]], 0] -> 
      Extract[puzzlePermutations[[x]][[i - 1]], 
       Position[puzzlePermutations[[x]][[i]], 0]]]], {x, 
   Length[puzzlePermutations]}, {i, 2, 5}];

From here, we just need to select the permutation(s) for which the columns in the top layer all add up to 42:

solution = Select[puzzlePermutations, ContainsExactly[Total@#[[5]], {42}] &];

This produces the sole solution to the puzzle, and we can see how we should turn each dial to solve it:

Array[MatrixForm[solution[[1]][[#]]] &, 5]

Array representing the solution.

Finally, thanks to a bit of Wolfram Language code, the solved puzzle:

enter image description here

I had fun working through this. I'm sure there are more efficient or elegant ways to write this code and solve the puzzle, and I'd love to hear your thoughts.

Thanks for reading!

Christopher

POSTED BY: Christopher Fox
2 Replies

enter image description here -- you have earned Featured Contributor Badge enter image description here Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

POSTED BY: Moderation Team

Very cool Christopher. Interesting approach and nice use of WL functions such as AssociationThread and patterns. On the website it has a difficulty of 5, I wonder the average time it takes to solve manually.

POSTED BY: Ahmed Elbanna
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract