Manuals, version 1
The presented code is written in C#.
The code was obtained using TDD approach. Each question has own set of tests, see Question1Tests.cs, etc.
The class Minisculus contains all methods needed to solve all five problems.
You can delete the Minisculus class and keep redeveloping it following the tests: red, green, refactor.
F5 runs the Console Application. This will show the answer for the fifth question and all possible wheel settings. ‘3’ stands for ‘03’.
The method DecodeWordForAllCombinations was initially used as a brute force to loop 100 times and costs O(n^2). Upon further development it was replaced by less costly EncodeWordForAllRequiredCombinations, which loops 21 times and returns a list of encoded words for all possible wheel settings. The method SubStringResponse uses it to see if the encoded words are contained in the coded message, and stops once found the encoded guess word (in this case loops only 4 times, max 21 times) and returns the wheels positions. Then the method WheelSettings produces all possible wheel setups based on the returned first wheel positions (loops 5 times). The 100 times loop was replaced by three loops, the current cost of looping: 21 + 4 + 5 = 30 times. It looks as not much was gained, but it is a backbone for more complicated algorithm, say with 4 wheels.
Refactor obeying the current Minisculus Challenge rules.
Plug into .NET MVC3 framework: http://krzysztofpazowski.com/Minisculus
- Encode any string, user selects first and second wheel positions
- Decode any string, user inserts a guess word
- The wheel rules are the same as in the Minisculus Challenge ( first – forward, second – twice backward, third – depends on second, forward)
- Programme Minisculus 6 :-)
- 4 wheels
- Allow any wheel movement: forward, backward.
- (Allow multiple wheel spinning up to 10 times.)
- Eg. Wheel One – 4 times backward, wheel two – 7 times forward, wheel three – 10 times backward, wheel four – 2 times forward.
- Decode message: “Not ready yet”
- Find all possible wheel positions.