How can I create an expression that uses numbers 1 - 7 to equal 100?

From a brute force Python program, here's the list of possible solutions. I apologize for the "mathematical duplicates" caused by the inclusion of parenthesis, but the list was too long to QC.

+1.0-2.0+3.0+(4.0*5.0-6.0)*7.0
+1.0-2.0+3.0+(4.0*(5.0)-6.0)*7.0
+1.0-2.0*3.0+(4.0+5.0+6.0)*7.0
+1.0-2.0*3.0+(4.0+(5.0)+6.0)*7.0
+1.0+(2.0+3.0)*4.0*5.0+6.0-7.0
+1.0+(2.0+3.0)*4.0*5.0+(6.0)-7.0
+1.0+(2.0+3.0)*4.0*(5.0)+6.0-7.0
+1.0-(2.0)+3.0+(4.0*5.0-6.0)*7.0
+1.0-(2.0)+3.0+(4.0*(5.0)-6.0)*7.0
+1.0-(2.0)*3.0+(4.0+5.0+6.0)*7.0
+1.0-(2.0)*3.0+(4.0+(5.0)+6.0)*7.0
-1.0+2.0*3.0*4.0+(5.0+6.0)*7.0
-1.0+2.0*(3.0*4.0*5.0-6.0)-7.0
-1.0+2.0*(3.0*4.0*(5.0)-6.0)-7.0
-1.0+2.0*(3.0*(4.0*5.0)-6.0)-7.0
-1.0+2.0*(3.0*(4.0)*5.0-6.0)-7.0
-1.0+2.0*(3.0)*4.0+(5.0+6.0)*7.0
-1.0*2.0+3.0*4.0*5.0+6.0*7.0
-1.0*2.0+3.0*4.0*5.0+(6.0)*7.0
-1.0*2.0+3.0*4.0*(5.0)+6.0*7.0
-1.0*2.0+3.0*(4.0*5.0)+6.0*7.0
-1.0*2.0+3.0*(4.0)*5.0+6.0*7.0
-1.0*2.0+3.0*(4.0)*5.0+(6.0)*7.0
-1.0*2.0-3.0+(4.0+5.0+6.0)*7.0
-1.0*2.0-3.0+(4.0+(5.0)+6.0)*7.0
-1.0*2.0+(3.0*4.0*5.0)+6.0*7.0
-1.0*2.0+(3.0*4.0)*5.0+6.0*7.0
-1.0*2.0+(3.0*4.0)*5.0+(6.0)*7.0
-1.0*2.0+(3.0*(4.0)*5.0)+6.0*7.0
-1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+6.0*7.0
-(1.0)*2.0+3.0*4.0*5.0+(6.0)*7.0
-(1.0)*2.0+3.0*4.0*(5.0)+6.0*7.0
-(1.0)*2.0+3.0*(4.0*5.0)+6.0*7.0
-(1.0)*2.0+3.0*(4.0)*5.0+6.0*7.0
-(1.0)*2.0+3.0*(4.0)*5.0+(6.0)*7.0
-(1.0)*2.0-3.0+(4.0+5.0+6.0)*7.0
-(1.0)*2.0-3.0+(4.0+(5.0)+6.0)*7.0
-(1.0)*2.0+(3.0*4.0*5.0)+6.0*7.0
-(1.0)*2.0+(3.0*4.0)*5.0+6.0*7.0
-(1.0)*2.0+(3.0*4.0)*5.0+(6.0)*7.0
-(1.0)*2.0+(3.0*(4.0)*5.0)+6.0*7.0
-(1.0)*2.0+(3.0)*4.0*5.0+6.0*7.0
-(1.0)*2.0+(3.0)*4.0*5.0+(6.0)*7.0
-(1.0)*2.0+(3.0)*4.0*(5.0)+6.0*7.0

Code used to generate list:

import itertools

signs = ('+','-','/','*','(',')','+(','-(','/(','*(',')+',')-',')/',')*')
nums = range(1,8)

for someSigns in itertools.product(signs,repeat=7):
    evalStr = ""
    for i, j in zip(someSigns, nums):
        evalStr += i + str(float(j))
    try:    
        if eval(evalStr) == 100:    
            print evalStr
    except:
        continue

$$-1\cdot2+3\cdot4\cdot5+6\cdot7$$ There is no general method that I am aware of.


Another way:

$$-1\cdot 2-3+(4+5+6)\cdot 7$$

Tags:

Arithmetic