[NON RESOLU] : Panne en Python...
Sujet : [NON RESOLU] : Panne en Python...
De : zzz (at) *nospam* aol.com (AIEO)
Groupes : fr.comp.lang.pythonDate : 02. Oct 2022, 02:56:10
Autres entêtes
Organisation : Aioe.org NNTP Server
Message-ID : <thar3q$hqs$1@gioia.aioe.org>
References : 1
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0
Le 28/09/2022 à 08:49, Dominique a écrit :
Bon, j'abdique. J'ai tenté avec itertools.permutations. Cette fonction est très intéressante, mais elle échoue avec 15 chiffres => freeze de mon PC !
J'ai recopié la solution du livre :
****************************
l15=[n for n in range(1,16)]
v=[[3,8,15],[7,14],[1,6,13],[5,12],[4,11],[3,10],[2,9],[1,8],[7],[6,15],[5,14],[4,13],[3,12],[2,11],[1,10]]
t=[]
for a in range(1,16):
for b in v[a-1]:
for c in v[b-1]:
for d in v[c-1]:
for e in v[d-1]:
for f in v[e-1]:
for g in v[f-1]:
for h in v[g-1]:
for i in v[h-1]:
for j in v[i-1]:
for k in v[j-1]:
for l in v[k-1]:
for m in v[l-1]:
for n in v[m-1]:
for o in v[n-1]:
t.append([a,b,c,d,e,f,g,h,i,j,k,l,m,n,o])
#print(t)
for l in t:
if sorted(l)==l15:
print(l)
****************************
Elle me donne deux réponses réciproques :
[8, 1, 15, 10, 6, 3, 13, 12, 4, 5, 11, 14, 2, 7, 9]
[9, 7, 2, 14, 11, 5, 4, 12, 13, 3, 6, 10, 15, 1, 8]
Mais je n'arrive pas bien à comprendre cette solution...
Haut de la page
Les messages affichés proviennent d'usenet.
NewsPortal