Guest User

Untitled

a guest
Oct 28th, 2020
16
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def iter_exprs(num_operands=None):
  2. if num_operands is None:
  3. i = 1
  4. while True:
  5. yield from iter_exprs(i)
  6. i += 1
  7. elif num_operands == 1:
  8. yield "1"
  9. else:
  10. for i in range(1, num_operands):
  11. for left in iter_exprs(i):
  12. for right in iter_exprs(num_operands-i):
  13. for operator in ["+", "*"]:
  14. yield f"({left}{operator}{right})"
  15.  
  16. for x in iter_exprs():
  17. print(x)
RAW Paste Data