Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.python > #3967

Re: [NON RESOLU] : Panne en Python...

Path csiph.com!weretis.net!feeder8.news.weretis.net!news.trigofacile.com!usenet-fr.net!.POSTED!not-for-mail
From Olivier Miakinen <om+news@miakinen.net>
Newsgroups fr.comp.lang.python
Subject Re: [NON RESOLU] : Panne en Python...
Date Sun, 2 Oct 2022 13:03:35 +0200
Organization There's no cabale
Lines 79
Message-ID <thbr67$1a61$1@cabale.usenet-fr.net> (permalink)
References <th0qot$afg6$1@dont-email.me> <thar3q$hqs$1@gioia.aioe.org>
NNTP-Posting-Host 220.12.205.77.rev.sfr.net
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-15
Content-Transfer-Encoding 8bit
X-Trace cabale.usenet-fr.net 1664708615 43201 77.205.12.220 (2 Oct 2022 11:03:35 GMT)
X-Complaints-To abuse@usenet-fr.net
NNTP-Posting-Date Sun, 2 Oct 2022 11:03:35 +0000 (UTC)
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.4
In-Reply-To <thar3q$hqs$1@gioia.aioe.org>
Xref csiph.com fr.comp.lang.python:3967

Show key headers only | View raw


Bonjour,

Le 02/10/2022 03:56, AIEO a écrit :
> 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 :

Je n'ai pas compris cette solution tout de suite, mais après un peu de réflexion
c'est ok.

> 
> ****************************
> 
> 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]]

Ici, pour un entier a donné entre 1 et 15, v[a-1] est l'ensemble des entiers b
entre 1 et 15 (différents de a) tels que a + b est un carré.

Par exemple pour a=3, v[2]=[1,6,13], et on a :
 3 + 1 = 4
 3 + 6 = 9
 3 + 13 = 16

[Note : il y a un nombre de trop dans v[]. Lequel est-ce ?]


> 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])

Ceci choisit pour chaque voisin d'un entier possible un autre entier tel que
la somme des deux soit un carré. Mais il est possible que la liste commence
par [1,3,1,... par exemple, où le nombre 1 est répété.

> #print(t)
> for l in t:
>      if sorted(l)==l15:

Là on trie la liste obtenue. Si tous les nombres sont différents, on doit
obtenir la liste triée des entiers de 1 à 15, c'est-à-dire l15.

>          print(l)

Seulement si c'est le cas, on affiche le résultat.

> ****************************
> 
> 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...

Voir l'explication ci-dessus.

Cordialement,
-- 
Olivier Miakinen

Back to fr.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Panne en Python... Dominique <zzz@aol.com> - 2022-09-28 08:49 +0200
  Re: Panne en Python... Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2022-09-28 16:11 +0200
  [NON RESOLU] : Panne en Python... AIEO <zzz@aol.com> - 2022-10-02 03:56 +0200
    Re: [NON RESOLU] : Panne en Python... Olivier Miakinen <om+news@miakinen.net> - 2022-10-02 13:03 +0200
    Re: [NON RESOLU] : Panne en Python... Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2022-10-02 13:35 +0200
      Re: [NON RESOLU] : Panne en Python... AIEO <zzz@aol.com> - 2022-10-02 14:58 +0200
        Re: [NON RESOLU] : Panne en Python... Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2022-10-02 15:58 +0200
          Re: [NON RESOLU] : Panne en Python... AIEO <zzz@aol.com> - 2022-10-02 16:32 +0200
            Re: [NON RESOLU] : Panne en Python... Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2022-10-02 17:51 +0200
  [RESOLU] : Panne en Python... Olivier Miakinen <om+news@miakinen.net> - 2022-10-02 18:05 +0200
    Re: [RESOLU] : Panne en Python... Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2022-10-02 21:22 +0200

csiph-web