Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def findThis(number, memorySafe=True, singleDigits=True, upto=100):
- constructRetVal = lambda x_, y_, op_: "{} {} {} = {}".format(x_, op_, y_, number)
- symbols = ["%", "^", "&", "*", "-", "+", ">>", "/"]
- if not memorySafe:
- symbols += ["<<", "**"]
- iterRange = range(10) if singleDigits else range(upto)
- found = []
- for x in iterRange:
- for y in iterRange:
- for operator in symbols:
- evalConstruct = "x {} y".format(operator)
- try:
- if eval(evalConstruct) == number:
- found.append(constructRetVal(x, y, operator))
- except ZeroDivisionError:
- pass
- return found
- # Demonstration
- # >>> findThis(69, singleDigits=False)
- # ['0 ^ 69 = 69',
- # '0 + 69 = 69',
- # '1 ^ 68 = 69',
- # '1 + 68 = 69',
- # '1 * 69 = 69',
- # '2 + 67 = 69',
- # ...
- # ...
- # ...
- # '87 ^ 18 = 69',
- # '87 - 18 = 69',
- # '87 & 69 = 69',
- # '87 & 77 = 69',
- # '88 - 19 = 69',
- # '88 ^ 29 = 69',
- # '89 - 20 = 69',
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement