Program to determine solution to math puzzle from the book "Hacking: The Art of Exploitation, 2nd Edition", by Jon Erickson. More...
Variables | |
| mathPuzzle.startT = monotonic_ns() | |
| Solver starting time. | |
| tuple | mathPuzzle.num = ('1','3','4','6') |
| Tuple of the four numbers that must be used (in string format) | |
| mathPuzzle.numLen = factorial(len(num)) | |
| Integer representing the total unique combinations of numbers. More... | |
| int | mathPuzzle.opRepeat = 3 |
| Number of operations needed to construct a possible solution. | |
| tuple | mathPuzzle.op = ('+','-','*','/','+(','-(','*(','/(',')+',')-',')*',')/') |
| Tuple of all possible operations. | |
| int | mathPuzzle.opLen = len(op)**opRepeat |
| Total number of combinations of three operations, with repeats allowed. | |
| int | mathPuzzle.ans = 0 |
| Initialize answer variable. | |
| int | mathPuzzle.counter = 1 |
| Counter variable for attempt number. | |
| mathPuzzle.numOptions = permutations(num) | |
| Intialize iterable for number sequences. | |
| mathPuzzle.nums = next(numOptions) | |
tuple of number sequence from iterable numOptions | |
| mathPuzzle.opOptions = product(op, repeat = opRepeat) | |
| all possible operations, found using product() | |
| mathPuzzle.ops = next(opOptions) | |
Tuple of operations from iterable opOptions | |
| string | mathPuzzle.ansString = '' |
| Initialized string for solution. | |
| string | mathPuzzle.parenthDiff = ansString.count('(') - ansString.count(')') |
| Integer value representing the number of ) needed to form a valid expression. | |
Program to determine solution to math puzzle from the book "Hacking: The Art of Exploitation, 2nd Edition", by Jon Erickson.
See source code here: https://bitbucket.org/ryanmclaug/me_405/src/master/mathPuzzle.py
| mathPuzzle.numLen = factorial(len(num)) |
Integer representing the total unique combinations of numbers.
For example: 1,3,4,6 is different than 6,4,1,3 from a solver standpoint