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


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

Panne en Python...

From Dominique <zzz@aol.com>
Newsgroups fr.comp.lang.python
Subject Panne en Python...
Date 2022-09-28 08:49 +0200
Organization A noiseless patient Spider
Message-ID <th0qot$afg6$1@dont-email.me> (permalink)

Show all headers | View raw


Bonjour,

Je poursuis avec "100 énigmes mathématiques résolues avec Python" et un 
exercice sur lequel je bute.

L'énoncé me donne cette liste :
liste=[2,14,11,5,8,12,6,3,1,9,7,13,5,4,10,15]

et me fait remarquer que la somme de chacun des trois premiers couples 
me donne un carré. Arrivé au 4e couple, il n'y a plus de carré (5+8)

Il m'est demandé "d'arranger la liste en 15 nombres entiers de 1 à 15 de 
telle sorte que la somme de 2 nombres voisins soit toujours un carré 
parfait".

J'ai créé une liste (resu) avec chaque couple susceptible de me donner 
un carré parfait :

liste=[2,14,11,5,8,12,6,3,1,9,7,13,5,4,10,15]
resu=[]
deb=[x for x in range(1,16)]
fin=[x for x in range(1,16)]
for i in deb:
     for j in fin:
         tot=i+j
         tot1=[i,j]
         tot1.sort()
         if tot1 not in resu and i!=j and tot**.5==int(tot**.5):
             resu.append(tot1)

Je ne suis pas sûr d'être parti dans la bonne direction. Ensuite, si 
oui, quelle indication me donneriez-vous pour répondre à la question ? 
Si non, quelle piste me faudrait-il explorer ?

Je précise que le livre donne la solution, mais je préfère un peu 
chercher par moi-même, mais là... :)

Merci et bonne journée,

Dominique

Back to fr.comp.lang.python | Previous | NextNext 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