>
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;
> occ(2,[1,2,2,4,6,2,8,5]);
>
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;
> occL(2,[1,2,2,4,6,2,8,5]);
>
swap:=proc(a::name, b::name)
local c;
c:=eval(a);
a:=eval(b);
b:=eval(c);
end;
>
a:=3;b:="choucroute";
swap(a,b);
a;b;
Error, swap expects its 1st argument, a, to be of type name, but received 3
>
a:=3;b:="choucroute";
swap('a','b'):
a;b;
>
mySort:=proc(L::name)
L:=sort(eval(L));
end;
>
L:=[1,2,2,4,6,2,8,5];
sort(L);
L;
mySort('L');
L;
>
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;
> myMember(8,[1,2,2,4,6,2,8,5],'pos');pos;
> myMember(2,[1,2,2,4,6,2,8,5],'pos');pos;
> myMember(7,[1,2,2,4,6,2,8,5],'pos');pos;
> #Problème
> Observations:=[[12,2,15],[27,5,8],[03,9,67],[32,1,90],[31,12,9]];
> Mois:=[31,28,31,30,31,30,31,31,30,31,30,31];nops(Mois);
>
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;
> numjour(Observations[1]);numjour(Observations[2]);numjour(Observations[3]);
>
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;
> correct([31,1,10]);correct([42,2,0]);correct([18,-5,12]);correct([18,2,-4]);
> remove(x->not correct(x),Observations);
>
>
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;
> Avant([3,2,10],[2,2,8]);
> Observations:=[[12,2,15],[27,5,8],[03,9,67],[31,12,9],[2,2,2],[4,9,1]];
> sort(Observations,Avant);
>