168k views
0 votes
Use all the non-zero digits (below), but only once each, to make any set of prime numbers:

1 2 3 4 5 6 7 8 9
What is the sum of this set of prime numbers?
Can you get a smaller sum with a different set of primes? (What is the smallest possible sum?)​

1 Answer

5 votes

Answer:

Hello,

Answer 207

Explanation:

[5, 29, 47, 61, 83, 225]

[5, 29, 41, 67, 83, 225]

[5, 23, 47, 61, 89, 225]

[5, 23, 41, 67, 89, 225]

[2, 5, 7, 43, 61, 89, 207]

[2, 3, 5, 47, 61, 89, 207]

[2, 3, 5, 41, 67, 89, 207]

import sys

#-------------------------------------------------------

def see(txt,arr):

print (txt,"=",end =" ")

for i in range(1,10 ):

if arr[i]:

print (i,end=" ")

print ()

#-------------------------------------------------------

def libre(p):

if p==0:

return True

if p<10:

a=p

if not(used[a]):

return True

else:

a=p//10

b=p%10

if not(used[a]) and not(used[b] ):

return True

return False

#-------------------------------------------------------

def store(p):

# on ne stock pas 0

global used

#print ("in store ",p)

if p==0:

return

if p<10:

used[p]=True

else:

a=p//10

b=p%10

used[a]=True

used[b]=True

return

def isSol():

global mini,k,mini_set,all_mini_set

for i in range(1,10):

if not used[i]:

return False

s=i_1+i_2+i_3+i_4+i_5+i_6+i_7+i_8+i_9

if s <= mini[0]:

if s < mini[0]:

k=k+1

mini[0]=s

mini[1]=i_1

mini[2]=i_2

mini[3]=i_3

mini[4]=i_4

mini[5]=i_5

mini[6]=i_6

mini[7]=i_7

mini[8]=i_8

mini[9]=i_9

a_set=sorted(set([i for i in mini if i >0] ))

if (a_set not in all_mini_set):

mini_set=a_set.copy()

all_mini_set.append(a_set)

print (a_set)

#print (mini,end="")

"""

see("used ",used)

see("sav_9",sav_9)

see("sav_8",sav_8)

see("sav_7",sav_7)

see("sav_6",sav_6)

see("sav_5",sav_5)

see("sav_4",sav_4)

see("sav_3",sav_3)

see("sav_2",sav_2)

see("sav_1",sav_1)

"""

#if k>2:

# sys.exit(0)

return True

#-------------------------------------------------------

#╚ 0 : ne pas utiliser

jeu=[

[],

[0,13, 17, 19, 31, 41, 61, 71],

[0,2,23,29],

[0,3,13,23,31,37,43,53,73,83],

[0,41,43,47],

[0,5,53,59],

[0,61,67],

[0,7,17,37,47,67,71,73,79,97],

[0,83,89],

[0,19,29,59,79,89,97]

]

print ("-------------------------------------------")

for i in range(10):

print (jeu[i])

print ("-------------------------------------------")

mini=[1000]+[0 for i in range(1,10) ]

mini_set={}

all_mini_set=[]

used=[False for i in range(10 )]

sav_1=used.copy()

k=0

for i_1 in jeu[1]:

used=sav_1.copy()

if libre(i_1):

store(i_1)

sav_2=used.copy()

for i_2 in jeu[2]:

used=sav_2.copy()

if libre(i_2):

store(i_2)

sav_3=used.copy()

for i_3 in jeu[3]:

used=sav_3.copy()

if libre(i_3):

store(i_3)

sav_4=used.copy()

for i_4 in jeu[4]:

used=sav_4.copy()

if libre(i_4):

store(i_4)

sav_5=used.copy()

for i_5 in jeu[5]:

used=sav_5.copy()

if libre(i_5):

store(i_5)

sav_6=used.copy()

for i_6 in jeu[6]:

used=sav_6.copy()

if libre(i_6):

store(i_6)

sav_7=used.copy()

for i_7 in jeu[7]:

used=sav_7.copy()

if libre(i_7):

store(i_7)

sav_8=used.copy()

for i_8 in jeu[8]:

used=sav_8.copy()

if libre(i_8):

store(i_8)

sav_9=used.copy()

for i_9 in jeu[9]:

used=sav_9.copy()

if libre(i_9):

store(i_9)

isSol()

used=sav_9.copy()

User Kanzure
by
4.9k points