Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. #!/usr/bin/python
  2. import itertools
  3.  
  4. def make_range(x):
  5.     x = eval(x)
  6.     if type(x) != type(()): # tuple
  7.         x = x,x
  8.     return xrange(x[0], x[1] + 1)
  9.  
  10. formula = raw_input()
  11. inp = raw_input()
  12. if not inp.split():
  13.     print eval(formula)
  14.     exit()
  15.  
  16. dic = {key:make_range(val) for key, val in map(lambda s: s.split("="), inp.split(" "))}
  17. import math
  18. math_map ={ i:j for i,j in zip(dir(math), map(lambda name: eval("math."+name), dir(math)))}
  19. print max(eval(formula, dict(math_map.items() + { k:j for k,j in zip(dic.keys(), i)}.items())) for i in itertools.product(*dic.values()) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement