>
restart;
with(stats):
with(stats[statplots]):
Convert:=proc(data)
local hap,hap1,d,j1,j2,j3,mean;
hap:=[];
hap1:=[];
d:=[];
for j1 from 1 to nops(data)
do
hap:=[op(hap),data[j1][2]];
od;
mean := nops(data)*describe[mean](hap);
for j2 from 1 to nops(data)
do
hap1:=[op(hap1), hap[j2]/mean];
od;
for j3 from 1 to nops(data)
do
d:=[op(d), [data[j3][1],hap1[j3]]];
od;
d;
end:
Bargraph:=proc(data,xmin,xmax,k)
local sorteddata,dx,graphicslist,f:
sorteddata:=[]:
dx:=(xmax-xmin)/k:
graphicslist:=[]:
sorteddata:=sort(data):
if ((op(1,sorteddata)<xmin) or (op(nops(sorteddata),sorteddata)>xmax))
then
lprint(`Note: some data values lie outside the user-defined interval.`):
fi:
f:=proc(k,sorteddata,xmin,dx,xmax)
local i,j,currentupperlim,leng,index,counter,result,finallist,q,numb,
linelist:
linelist:=[]: finallist:=[]:
index:=1:
leng:=nops(sorteddata):
currentupperlim:=xmin+dx:
result:=[]:
for q from 1 to leng do
if ((op(q,sorteddata)>=xmin) and (op(q,sorteddata)<=xmax))
then finallist:=[op(finallist),op(q,sorteddata)]
fi:
od:
numb:=nops(finallist):
for i from 1 to k do
counter:=0:
while ((index<=numb) and (op(index,finallist)<=currentupperlim)) do
counter:=counter+1:
index:=index+1:
od:
result:=[op(result),counter]:
currentupperlim:=currentupperlim+dx:
od:
for j from 1 to k do
linelist:=[op(linelist),[xmin + (j-1)*dx,0]]:
linelist:=[op(linelist),[xmin + (j-1)*dx,op(j,result)/leng]]:
linelist:=[op(linelist),[xmin + j*dx,op(j,result)/leng]]:
linelist:=[op(linelist),[xmin + j*dx,0]]:
od:
plot(linelist,style=LINE);
end:
f(k,sorteddata,xmin,dx,xmax):
end:Areabargraph:=proc(data,xmin,xmax,k)
local sorteddata, dx, lines,graphicslist, f:
sorteddata:=[]:
dx:=(xmax-xmin)/k:
lines:=[]:
graphicslist:=[]:
sorteddata:=sort(data):
if ((op(1,sorteddata)<xmin) or (op(nops(sorteddata),sorteddata)>xmax))
then
lprint(`Note: some data values lie outside the user-defined interval.`)
fi:
f:=proc(k,sorteddata,xmin,dx,xmax,lines::evaln)
local i,j,currentupperlim,leng,index,counter,result,
finallist,q,numb,linelist:
finallist:=[]:
linelist:=[]:
index:=1:
leng:=nops(sorteddata):
currentupperlim:=xmin+dx:
result:=[]:
for q from 1 to leng do
if ((op(q,sorteddata)>=xmin) and (op(q,sorteddata)<=xmax))
then finallist:=[op(finallist),op(q,sorteddata)]
fi:
od:
numb:=nops(finallist):
for i from 1 to k do
counter:=0:
while ((index<=numb) and (op(index,finallist)<=currentupperlim)) do
counter:=counter+1:
index:=index+1:
od:
result:=[op(result),counter]:
currentupperlim:=currentupperlim+dx:
od:
for j from 1 to k do
linelist:=[op(linelist),[xmin + (j-1)*dx,0]]:
linelist:=[op(linelist),[xmin + (j-1)*dx,op(j,result)/(leng*dx)]]:
linelist:=[op(linelist),[xmin + j*dx,op(j,result)/(leng*dx)]]:
linelist:=[op(linelist),[xmin + j*dx,0]]:
od:
lines:=linelist:
end:
f(k,sorteddata,xmin,dx,xmax,lines):
plot(lines,style=LINE);
end:

Analysis:=proc(L)
local m,v,sd,k,S,i,j,l;
m:=0;
v:=0;
sd:=0;
for k from 1 to nops(L)
do
m:=m+L[k];
od;
m:=evalf(m/nops(L));
for i from 1 to nops(L)
do
v:=v+(L[i]-m)^2;
od;
v:=evalf(v/nops(L));
sd:=evalf(sqrt(v));
[m,v,sd];
end:

Histogram:=proc(d,n)
local list1,j1,j2,A,ml,mh,sl,sh,Al,Ah,L;
L:=list1;
Al:=Analysis(d);
ml:=Al[1];
sl:=Al[3];
lprint("the Mean is",ml);
lprint("the Standard deviation is",sl);
lprint("A histogram looks like");
Areabargraph(d,min(op(d))-.5,max(op(d))+.5,n );
end:

Histogram2:=proc(d,n)
local list1,j1,j2,A,ml,mh,sl,sh,Al,Ah,L;
L:=list1;
Al:=Analysis(d);
ml:=Al[1];
sl:=Al[3];
lprint("the Mean is",ml);
lprint("the Standard deviation is",sl);
end:

> R:=rand();
randomize(R);

StkG2:=proc(view)
local U,C,r,i;
C:=0;
U:=0;
for i from 1 while U<>1
do
C:=C+1:
r:=stats[random, discreteuniform[0,1]](1);
if view=show
then
lprint(r);
fi;
if
r=1
then U:=1
fi;
od:
C^2;

end:

R := 427419669081

427419669081

> StkG2(show);

0

0

0

1

16

> ManyStk2:=proc(m,k)
local i,L;
L:=[];
for i from 1 to m
do
L:=[op(L),StkG2(noshow)];
od:
lprint("the maximum win was", max(op(L)));
Histogram2(L,k);
end:

> ManyStk2(1000,10);

"the maximum win was", 100

"the Mean is", 5.599000000

"the Standard deviation is", 8.877961371

> ManyStk2(10000,10);

"the maximum win was", 169

"the Mean is", 5.856800000

"the Standard deviation is", 10.43066213

> ManyStk2(100000,10);

"the maximum win was", 400

"the Mean is", 5.957870000

"the Standard deviation is", 10.50161561

>