Guest User

Untitled

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