Facebook Superpatterns puzzle - The solution 2
My earlier blog post had a brute force approach to solving the super patterns puzzle. The order of the program was in the order of n!. Didnt think it was worth coding it up. Might use it to validate this new solution. The solution is based on building larger superpatterns from smaller ones. This is how the solution would look like ..
Take a 2 -subpattern for eg. The subpatterns would be
{1,2} and {2,1} .. the superpattern is {1,3,2} other "superpatterns" that are not combinatorially smallest are {2,1,3}, {2,3,1} and {3,1,2}.
We can build higher superpattern from lower ones like this.
For the 2-subpatterns to become a 3 -subpatterns, it would have to satisfy ..
{3,1,2}
{3,2,1}
{1,3,2}
{2,3,1}
{1,2,3}
{2,1,3}
Which in a way means that we will have to add a "higher" element in the sequence or superpatterns that generated the lower or 2-subpatterns to get the 3-subpattern.
The trick if figuring out the smallest combination of adding this additional number. More commong soon ...