Skip to main content
added 4 characters in body
Source Link
Carl Löndahl
  • 5.3k
  • 1
  • 19
  • 29

Turns out there are two solutions: 171$171$ and 341$341$ (unless I made a terrible mistake; I have checked this using some Python code).

L = [1,2,4,8,16,32,64,128,256,512]
Q = [0]*(sum(L)+1)
def rec(Q, L, i, s, f):
    if i == len(L):
        if s > 0:
            Q[s] += 1
        if s == 171: # change to see sets for 341
            print f, sum(f)
        return
    f.append(L[i])
    rec(Q, L, i+1, s + L[i], f)
    f.pop()
    f.append(-L[i])
    rec(Q, L, i+1, s - L[i], f)
    f.pop()
    rec(Q, L, i+1, s, f)
rec(Q,L,0,0,[])
print "Possible solutions:"
for i in range(0,len(Q)): 
    if Q[i] == 89: print i

Turns out there are two solutions: 171 and 341 (unless I made a terrible mistake; I have checked this using some Python code).

L = [1,2,4,8,16,32,64,128,256,512]
Q = [0]*(sum(L)+1)
def rec(Q, L, i, s, f):
    if i == len(L):
        if s > 0:
            Q[s] += 1
        if s == 171: # change to see sets for 341
            print f, sum(f)
        return
    f.append(L[i])
    rec(Q, L, i+1, s + L[i], f)
    f.pop()
    f.append(-L[i])
    rec(Q, L, i+1, s - L[i], f)
    f.pop()
    rec(Q, L, i+1, s, f)
rec(Q,L,0,0,[])
print "Possible solutions:"
for i in range(0,len(Q)): 
    if Q[i] == 89: print i

Turns out there are two solutions: $171$ and $341$ (unless I made a terrible mistake; I have checked this using some Python code).

L = [1,2,4,8,16,32,64,128,256,512]
Q = [0]*(sum(L)+1)
def rec(Q, L, i, s, f):
    if i == len(L):
        if s > 0:
            Q[s] += 1
        if s == 171: # change to see sets for 341
            print f, sum(f)
        return
    f.append(L[i])
    rec(Q, L, i+1, s + L[i], f)
    f.pop()
    f.append(-L[i])
    rec(Q, L, i+1, s - L[i], f)
    f.pop()
    rec(Q, L, i+1, s, f)
rec(Q,L,0,0,[])
print "Possible solutions:"
for i in range(0,len(Q)): 
    if Q[i] == 89: print i
Source Link
Carl Löndahl
  • 5.3k
  • 1
  • 19
  • 29

Turns out there are two solutions: 171 and 341 (unless I made a terrible mistake; I have checked this using some Python code).

L = [1,2,4,8,16,32,64,128,256,512]
Q = [0]*(sum(L)+1)
def rec(Q, L, i, s, f):
    if i == len(L):
        if s > 0:
            Q[s] += 1
        if s == 171: # change to see sets for 341
            print f, sum(f)
        return
    f.append(L[i])
    rec(Q, L, i+1, s + L[i], f)
    f.pop()
    f.append(-L[i])
    rec(Q, L, i+1, s - L[i], f)
    f.pop()
    rec(Q, L, i+1, s, f)
rec(Q,L,0,0,[])
print "Possible solutions:"
for i in range(0,len(Q)): 
    if Q[i] == 89: print i