This problem challenges you to discover algorithm(s) to simplify and solve a well defined logic puzzle, given that for a contest lasting only a few hours, a brute force algorithm could take days of run-time to complete.

This problem is inspired by Project Euler 185: http://projecteuler.net/problem=185

This problem is like the Project Euler problem, except instead of numbers, lowercase letters are used. The integer following each sequence of 15 letters reflects the number of correct letters in the correct position.

This problem could have 0, just 1, or possibly many solutions. Your job is to find the solutions.

Show solution

Hide solution

Hint 1: There are, at maximum, 26^15 possible solutions.

Hint 2: If you look just at the test patterns with 0 letters correct and in the correct position, you can rule out certain letters from occurring in a solution. For example, the third test pattern, 'befreedjustlike', tells us that 'b' cannot occur in the first position, 'e' cannot occur in the second position, and so on. We know that there can be no v's, because of the test patterns, 'vvvvvvvvvvvvvvv 0'.

Hint 3: Find a test pattern with exactly 1 letter correct and in the correct position. Of the letters that have not been ruled out from occurring at their respective positions, if you assume, one at a time, that each letter is correct, you can recursively look for just the solutions that contain that letter at that position (it is recursive because you can do the same for the other test patterns that have 1 letter correct in the correct position).

Hint 4: Consider using the following arrays to store information:- "assumedLetters", an array that is the same length as a solution (15), which contains the letters that we are assuming to be correct in their respective positions at any given time. For example, if we assume that the first letter is a 'd', assumedLetters[0] would be 'd'.- "cannotOccur", an array of arrays that indicates whether certain letters at certain positions can occur. For example, if 'x' cannot occur at the second position, cannotOccur[1]['x' - 'a'] would be True. We subtract 'a' so that the inner array is not bigger than 26 letters.- "numAssumptionsLeft", an array of integers, one for each test pattern. The values in this array start out equal to the number of correct letters in the correct position for each test pattern. Each time we make an assumption that a letter is correct, we decrement this value.- "lastChecked", an array that keeps track of the last letter we checked in each test pattern. This allows us to find every permutation of possible solutions based on the letters that exist in the test patterns.

A full solution can be found in the attached resources. The solution is written in C and is serial (not parallel). See the C source file for the full documentation.

The solution comes with a Makefile that can be used to compile the code by entering "make -f secretMessage_Makefile" in a Unix-style terminal. This will produce an executable file called "secretMessage".

To run the program enter "./secretMessage". The input file "testPatterns.txt" must be in the same directory. The output will be a list of all of the possible solutions.

This solution was timed on a LittleFe node (Intel Atom D525, 1.8 GHz) at 58.271 seconds using the Linux "time" command: "time ./secretMessage"