Python Assignment #1 – Combination Lock Puzzle
There is a popular puzzle where you try to guess the combination to a lock given some clues. For our purposes, the lock has exactly three wheels, each with values 0 through 9. (The answer is 042)
You must provide the clues on the command line and they must be of the form XYZ-R-W where:
XYZ = a possible combination of 3 digits, each 0-9
R = count of wheels that are the right digit in the right place (0-3)
W = count of wheels that are the right digit but in the wrong place (0-3)
The expectation is that you will use a brute form technique to solve this puzzle. Iterate through all 1,000 possible combinations and see which one(s) pass all the clues. Do NOT try to solve this puzzle the way a human would, using logic.
Additional rules:
- The number of clues can vary. If no clues are given you must print an error message.
- You must use a regular expression to validate the XYZ-R-W syntax.
- You do not need to do any additional validation of the XYZ, R, W parameters.
- You must print the list of clues given, all on one line.
- You must count the number of solutions found and print that count.
- If no solutions are found, you must print a message to that effect.
$ python3 lock.py
Need to give some patterns of the form XYZ-R-W
# This is the sample from the picture above
$ python3 lock.py 682-1-0 614-0-1 206-0-2 738-0-0 380-0-1
Trying 682-1-0 614-0-1 206-0-2 738-0-0 380-0-1
*** Solution #1 is … (there is exactly one answer, hidden)
$ python3 lock.py 682-1-0 614-0-1 206-0-2 738-0-0 380-0-1 314-1-0
Trying 682-1-0 614-0-1 206-0-2 738-0-0 380-0-1 314-1-0
No Solutions Found
$ python3 lock.py 682-0-0 614-0-0 206-0-0 738-0-0
Trying 682-0-0 614-0-0 206-0-0 738-0-0
*** Solution #1 is 555
*** Solution #2 is 559
*** Solution #3 is 595
*** Solution #4 is 599
*** Solution #5 is 955
*** Solution #6 is 959
*** Solution #7 is 995
*** Solution #8 is 999
$ python3 lock.py 682-1-0 614-0-1 w06-0-2 738-0-0 380-0-1
Invalid argument: w06-0-2
# The 4 is invalid, must be 0-3
$ python3 lock.py 682-1-0 614-0-1 206-0-2 738-4-0 380-0-1
Invalid argument: 738-4
The post Python Assignment #1 – Combination Lock Puzzle appeared first on My Assignment Online.