Created
June 20, 2010 16:39
-
-
Save makimoto/445940 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' | |
a solver for http://twitter.com/not522/status/16626276702 | |
''' | |
from sys import argv | |
from itertools import permutations,product | |
ops = ['+','-','*','/'] | |
parns = ['', '(', ')' ] | |
nums = map(float,argv[1:]) | |
for n in permutations(nums): | |
for o in product(ops, repeat = len(nums) -1): | |
for p in product(parns, repeat = len(nums) * 2): | |
e = '' | |
for i in xrange(len(nums)-1): | |
e += '%s %f %s %s ' % (p[i * 2], n[i], p[i * 2 - 1], o[i]) | |
e += '%s %f %s' % (p[-2], n[-1], p[-1]) | |
try: | |
ans = eval(e) | |
if 3.13 < ans < 3.15: | |
print(e + ' = %0.2f' % ans) | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment