Permutation test: Difference between revisions

No edit summary
Line 839:
> : 12.8% 11827
</pre>
 
Slower version, using a lambda function with a series of inner lambda functions to return each combination at a time.
 
<lang M2000 Interpreter>
Module CheckThis {
Function CombinationsStep (a, nn) {
c1=lambda (&f, &a) ->{=car(a) : a=cdr(a) : f=len(a)=0}
m=len(a)
c=c1
n=m-nn+1
p=2
while m>n {
c1=lambda c2=c,n=p, z=(,) (&f, &m) ->{if len(z)=0 then z=cdr(m)
=cons(car(m),c2(&f, &z)):if f then z=(,) : m=cdr(m) : f=len(m)+len(z)<n
}
c=c1
p++
m--
}
=lambda c, a (&f) ->c(&f, &a)
}
treated=(85, 88, 75, 66, 25, 29, 83, 39, 97)
placebo=(68, 41, 10, 49, 16, 65, 32, 92, 28, 98)
treat=0
m=each(treated): while m {treat+=array(m)}
total=1
for i=len(placebo)+1 to len(placebo) +len(treated):total*=i:next i
for i=len(placebo)-1 to 1: total/=i:next i
d=total div 10**int(log(total))
k=false
StepA=CombinationsStep(cons(treated, placebo),len(treated))
counter=0
gt=0
While not k {
comb=StepA(&k)
accu=0
m=each(comb)
while m {accu+=array(m)}
gt+=if(accu>treat->1,0)
counter++
if counter mod d=0 then Print over str$(counter/total," #0.0%"): Refresh 1000
}
print over str$(counter/total," #0.0%"):Refresh
print
lt=total-gt
print Format$("less or equal={0:1}%, greater={1:1}%, total={2}",gt/total*100, lt/total*100, total)
}
CheckThis
</lang>
 
=={{header|Mathematica}}==
Anonymous user