"'O
0
c
:J
0
:<:;
li)
.,,
..--t
c::
:l
0
~
N
"
@
~
.......
0
J::
:;
O'l
"'
·;::::
c::
0
>c::
o.
c::
0
.9
u
ü
:l
.,,
2
o.
~
"
:;
0
11
.,,
0
c:
:l
0
QJ
· Examen 2 - La suite de Syracuse
Fonction suivant(n: entier)
Début
Si n== l Alors
1
Retourner(l)
SinonSi n%2==0 Alors
1
retourner(n//2)
Sinon
J
Retourner(3 '"n+ l)
FinSi
Fin Fonction
Fonctions ............................ .
#type du résultat : entier
Fonction trajet(n : entier)
#type du résultat : liste
Variable(s) locale(s) et type(s) : L (liste)
Début
L - []
#Initialisation : liste vide
TantQue suivant(n)!= l Faire
1
Ajouter suivant(n) à L
n - suivant(n)
# n devient suivant(n)
FinTantQue
Ajouter l à L
Retourner(L)
Fin Fonction
Fonction max(n: entier)
# type du résultat : entier
Variable(s) locale(s) et type(s) : k, maxi (entiers)
Début
maxi - 0
#Initialisation : maxi=O
Pour k de 0 à longueur(trajet(n))-1 Faire #parcours des éléments de trajet(n)
Si maxi < trajet(n)[k] Alors
J
maxi - trajet(n)[k]
# maxi devient trajet(n)[k] si maxi < trajet(n)[k]
Fin Si
Retourner(maxi)
Fin Fonction
. .. ....... . . . ... .. ... . ... . Partie principale .. .. ... . . . . . .. . ....... . .
Début
N - 2
# initialisation de N : plus petit nombre de départ
TantQue longueur(trajet(N))!=30 Faire
J
N - N+l
FinTantQue
Afficher "Le nombre cherché est ",N,". Le plus grand nombre rencontré
est", max(N),"."
Fin
Partie B: implémentation Python et exécution
######################### F onct i ons #############################
d ef s ui va nt ( n ):
i f n == l:
r etu rn(I )
e 1 i f n %2 = = 0 :
r et ur n( n //2)
e 1 se :
r etu r n(3 * n + l )
257
0
c
:J
0
:<:;
li)
.,,
..--t
c::
:l
0
~
N
"
@
~
.......
0
J::
:;
O'l
"'
·;::::
c::
0
>c::
o.
c::
0
.9
u
ü
:l
.,,
2
o.
~
"
:;
0
11
.,,
0
c:
:l
0
QJ
· Examen 2 - La suite de Syracuse
Fonction suivant(n: entier)
Début
Si n== l Alors
1
Retourner(l)
SinonSi n%2==0 Alors
1
retourner(n//2)
Sinon
J
Retourner(3 '"n+ l)
FinSi
Fin Fonction
Fonctions ............................ .
#type du résultat : entier
Fonction trajet(n : entier)
#type du résultat : liste
Variable(s) locale(s) et type(s) : L (liste)
Début
L - []
#Initialisation : liste vide
TantQue suivant(n)!= l Faire
1
Ajouter suivant(n) à L
n - suivant(n)
# n devient suivant(n)
FinTantQue
Ajouter l à L
Retourner(L)
Fin Fonction
Fonction max(n: entier)
# type du résultat : entier
Variable(s) locale(s) et type(s) : k, maxi (entiers)
Début
maxi - 0
#Initialisation : maxi=O
Pour k de 0 à longueur(trajet(n))-1 Faire #parcours des éléments de trajet(n)
Si maxi < trajet(n)[k] Alors
J
maxi - trajet(n)[k]
# maxi devient trajet(n)[k] si maxi < trajet(n)[k]
Fin Si
Retourner(maxi)
Fin Fonction
. .. ....... . . . ... .. ... . ... . Partie principale .. .. ... . . . . . .. . ....... . .
Début
N - 2
# initialisation de N : plus petit nombre de départ
TantQue longueur(trajet(N))!=30 Faire
J
N - N+l
FinTantQue
Afficher "Le nombre cherché est ",N,". Le plus grand nombre rencontré
est", max(N),"."
Fin
Partie B: implémentation Python et exécution
######################### F onct i ons #############################
d ef s ui va nt ( n ):
i f n == l:
r etu rn(I )
e 1 i f n %2 = = 0 :
r et ur n( n //2)
e 1 se :
r etu r n(3 * n + l )
257
