> occ:=proc(x,L)
local i,count;

count:=0;
for i from 1 to nops(L) do
if L[i]=x then
count:=count+1;
fi;
od;
RETURN(count);
end;

[Maple Math]

> occ(2,[1,2,2,4,6,2,8,5]);

[Maple Math]

> occL:=proc(x,L)
local i,L2;

L2:=[];
for i from 1 to nops(L) do
if L[i]=x then
L2:=[op(L2),i];
fi;
od;
RETURN(L2);
end;

[Maple Math]

> occL(2,[1,2,2,4,6,2,8,5]);

[Maple Math]

> swap:=proc(a::name, b::name)
local c;

c:=eval(a);
a:=eval(b);
b:=eval(c);
end;

[Maple Math]

> a:=3;b:="choucroute";
swap(a,b);
a;b;

[Maple Math]

[Maple Math]

Error, swap expects its 1st argument, a, to be of type name, but received 3

[Maple Math]

[Maple Math]

> a:=3;b:="choucroute";
swap('a','b'):
a;b;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

> mySort:=proc(L::name)
L:=sort(eval(L));
end;

[Maple Math]

> L:=[1,2,2,4,6,2,8,5];
sort(L);
L;
mySort('L');
L;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

> myMember:=proc(x::anything,L::list,pos::name)
local i;

for i from 1 to nops(L) do
if L[i]=x then
pos:=i;
RETURN(true);
fi;
od;
RETURN(false);
end;

[Maple Math]

> myMember(8,[1,2,2,4,6,2,8,5],'pos');pos;

[Maple Math]

[Maple Math]

> myMember(2,[1,2,2,4,6,2,8,5],'pos');pos;

[Maple Math]

[Maple Math]

> myMember(7,[1,2,2,4,6,2,8,5],'pos');pos;

[Maple Math]

[Maple Math]

> #Problème

> Observations:=[[12,2,15],[27,5,8],[03,9,67],[32,1,90],[31,12,9]];

[Maple Math]

> Mois:=[31,28,31,30,31,30,31,31,30,31,30,31];nops(Mois);

[Maple Math]

[Maple Math]

> numjour:=proc(obs)
local i,num;

num:=0;
for i from 1 to (obs[2]-1) do
num:=num+Mois[i];
od;
RETURN(num+obs[1]);
end;

[Maple Math]

> numjour(Observations[1]);numjour(Observations[2]);numjour(Observations[3]);

[Maple Math]

[Maple Math]

[Maple Math]

> correct:=proc(x)

if x[2]<1 or x[2]>12 then
RETURN(false);
elif x[1]<1 or x[1]>Mois[x[2]] then
RETURN(false);
elif x[3]<0 then
RETURN(false);
else
RETURN(true);
fi;
end;

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

> correct([31,1,10]);correct([42,2,0]);correct([18,-5,12]);correct([18,2,-4]);

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

> remove(x->not correct(x),Observations);

>

[Maple Math]

> Avant:=proc(x,y)
if(x[2]<y[2]) then
RETURN(true);
elif x[2] = y [2] and x[1] < y[1] then
RETURN(true);
fi;
RETURN(false);
end;

[Maple Math]

> Avant([3,2,10],[2,2,8]);

[Maple Math]

> Observations:=[[12,2,15],[27,5,8],[03,9,67],[31,12,9],[2,2,2],[4,9,1]];

[Maple Math]

> sort(Observations,Avant);

[Maple Math]

>