(newRPL) Mastermind solver - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (newRPL) Mastermind solver (/thread-20399.html) |
(newRPL) Mastermind solver - Gilles - 08-26-2023 03:22 PM This small program plays the role of the decoder in the classic Mastermind game (4 holes, 6 colors). It uses newRPL LstX library v1.01d Code: DIRECTORY To use it: - Think of a combination (a combination of 4 digits, with numbers from 1 to 6, for example 4524) - Press 'Init', a combination proposal is made by the calculator - Enter according to the rule of the Mastermind the number of correctly placed digits and fine but misplaced digits in the form of a list { well placed, misplaced } - Press Guess, a new guess is made, answer as in the previous point then 'Guess' etc until the solution is found. About the algorithm: The algorithm is simple: - Init generates all the possible combinations (Cartesian product: 1296 possibilities) and stores them as a list in the "Pool" variable. It offers a first random proposal. - At each game turn, the program deletes in 'Pool' all the impossible solutions (this replays the last attempt and checks that the answer is correct), and chooses a new random proposal from the update 'Pool' list - We start all over again with new guess until the prg found the solution That's all ;D Very simple but very effective! Nota : It could be easily adapted for stock RPL and ListExt library |