Given six numbers and one target number, try to generate the target by using standard operations (+, -, *, /) on the six numbers. No number can be used more than once. Normal rules will restrict the number of 'large' (> 25) and 'small' numbers. Here, any input is accepted.
Reverse Polish Notation (RPN). I discovered this thanks to this blog.
python numbers_async.py
, then follow instructions. 10 solutions are found by default, change the NO_OF_SOLUTIONS
variable
in numbers_async.py
to change this.
- Compute all combinations of operators (5 operators with repeats results is 56 permutations).
- For each combination of operators, find all permutations of those operators with the numbers. There should now be
56 lists of permutations, each with a length of 39916800. An example permutation is:
(1, '+', 2, 3, '*', 4, 5, 6, '+', '+', '-')
- Loop through all 56 lists, concurrently, and compute each value.
- Once a solution is found, add it to a common set of solutions.
- Stop when the number of solutions is equal to the required value.
pypy3 numbers_sync.py
, then follow instructions (standard Python is about 25x slower).
- Compute all combinations of operators (5 operators with repeats results is 56 permutations).
- Loop through operator combinations. For each combination:
- Find all permutations of operators mixed with the numbers (39916800 permutations if 6 numbers).
- Compute the value of each permutation (making use of RPN notation).
- Exit if match is found.
Given some random letters, try to generate the longest word possible.
python letters.py
, then follow instructions.
Note that the Unix "words" file, found in /usr/share/dict/words
, is used as a dictionary so this script probably wont work on Windows.
My (not so nice) implementation when I was first learning Python.