> # Controle continu F. Balbo.
#Exo1

> #methode naïve: Une boucle pour calculer chaque terme, une boucle pour calculer l'ensemble de la somme.

S1:=proc(n::posint)
local i,j,somme,terme;

somme:=0;

for j from 1 to n do
terme:=0;

for i from 1 to j do
terme:=terme + i;
od;

somme:=somme+terme;
od;

RETURN(somme);
end;

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

> S1(1);S1(3);S1(10);

[Maple Math]

[Maple Math]

[Maple Math]

> #methode efficace: une seule boucle
#On peut remarquer que chaque terme t(n+1) = t(n)+n

S1eff:=proc(n::posint)
local i,somme,terme;

somme:=0;
terme:=0;
for i from 1 to n do
terme:=terme+i;
somme:=somme+terme;
od;
RETURN(somme);
end;

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

> S1eff(1);S1eff(3);S1eff(10);

[Maple Math]

[Maple Math]

[Maple Math]

> #exo2
#partie 1
palindrome:=proc(L::list)
local i;

for i from 1 to nops(L)/2 do
if(L[i]<>L[-i]) then
RETURN(false);
fi;
od;
RETURN(true);
end;

[Maple Math]
[Maple Math]

> palindrome([1,2,3,2,1]);palindrome([1,2,3,3,2,1]);palindrome([1,2,3,3,1]);

>

[Maple Math]

[Maple Math]

[Maple Math]

> #partie 2
creerPalindrome:=proc(L)
local i,L2;
L2:=L;

for i from nops(L) to 1 by -1 do
L2:=[op(L2),L[i]];
od;
RETURN(L2);
end;

[Maple Math]

> creerPalindrome([1,2,2,3,3,1]);creerPalindrome([1,2,3,4,5]);

[Maple Math]

[Maple Math]

> #Exo3
triMinimum:=proc(L)
local i, j, tmp, mini, L1;

L1:=L;

for i from 1 to nops(L1) do

#recherche du minimum
mini:=i;
for j from i to nops(L1) do
if(L1[j]<L1[mini]) then
mini:=j;
fi;
od;

#echange de la valeur indice avec le minimum
tmp:=L1[i];
L1[i]:=L1[mini];
L1[mini]:=tmp;

od;

RETURN(L1);
end;

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

> triMinimum([53,23,89,13,97,5,18,46]);

[Maple Math]

>
#Exo4

permutation:=proc(L1,L2)
local i,pos;

if nops(L1)<>nops(L2) then RETURN(false); fi;

for i from 1 to nops(L1) do
if not member(L1[i],L2,'pos') then
RETURN(false);
fi;
od;

RETURN(true);
end;

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

> permutation([1,a,b,2,3],[2,b,a,1,3]);

[Maple Math]

>