Search code examples
algorithmpuzzlegraph-algorithm

Instant insanity(4 cubes puzzle) algorithm


I am trying to find an algorithm to solve the instant insanity puzzle. Here is the wiki link for the problem. http://en.wikipedia.org/wiki/Instant_Insanity

From wikipedia I found a graph theory algorithm to solve the puzzle. Another solution is brute force method of trying all possibilities. I am not sure how complicated it will be to code using graph theory algorithm. I have to complete the coding within a day. It will helpful if anyone can tell a better way to approach this.


Solution

  • Since you mention the brute force solution, does that mean that it is an acceptable solution? Or do you really need to come up with an algorithm?

    A brute force approach only requires ~30K trials, so that means that your program will finish a few seconds after you write it ;-)

    A brute force algorithm outline might look like:

    for o1 in OrientationOptions {
     for o2 in OrientationOptions {
      for o3 in OrientationOptions {
       for o4 in OrientationOptions {
        if (isValidChoice (c1.o1, c2.o2, c3.o3, c4.4o)) {
         outputChoice();
         return;
        }
       }
      }
     }
    }