Combinations and permutations: Difference between revisions

no edit summary
No edit summary
Line 1,174:
1000 C 333 = 5776134553147651669777486323549601722339... (235 more digits)
</pre>
=={{header|M2000 Interpreter}}==
<lang M2000 Interpreter>
Module PermComb {
Form 80, 50
perm=lambda (x,y) ->{
def i,z
z=1
For i=x-y+1 to x :z*=i:next i
=z
}
fact=lambda (x) ->{
def i,z
z=1
For i=2 to x :z*=i:next i
=z
}
comb=lambda (x as decimal, y as decimal) ->{
If y>x then {
=0
} else.if x=y then {
=1
} else {
if x-y<y then y=x-y
def decimal i, z=1, ym
ym=y
For i=x to x-y+1
z*=i
z=z/ym
ym-- : if ym<1 then ym=1@
next i
=round(z,0)
}
}
Document Doc$
WriteLn("-- Permutations - from 1 to 12")
For i=1 to 12
l$="" : For j=1 to i : l$+= format$("P({0},{1})={2} ",i, j,perm(i, j)) :next j
Writetext(l$)
next i
WriteLn("-- Combinations from 10 to 60")
For i=10 to 60 step 10
l$="" : For j=1 to i step i div 5 : l$+= format$("C({0},{1})={2} ",i, j,comb(i, j)) :next j
Writetext(l$)
Next i
WriteLn("-- Permutations from 5000 to 15000")
For i=5000 to 15000 step 5000
l$="" : For j=10 to 70 step 20: l$+= format$("P({0},{1})={2} ",i, j,perm(i, j)) :next j
Writetext(l$)
Next i
WriteLn("-- Combinations from 200 to 1000")
For i=200 to 1000 step 200
l$="" : For j=20 to 100 step 20: l$+= format$("C({0},{1})={2} ",i, j,comb(i, j)) :next j
Writetext(l$)
Next i
ClipBoard Doc$
Sub WriteText(a$)
doc$=a$+{
}
Report a$
End Sub
Sub WriteLn(a$)
doc$=a$+{
}
Print a$
End Sub
}
PermComb
</lang>
{{out}}
-- Permutations - from 1 to 12
 
P(1,1)=1
P(2,1)=2 P(2,2)=2
P(3,1)=3 P(3,2)=6 P(3,3)=6
P(4,1)=4 P(4,2)=12 P(4,3)=24 P(4,4)=24
P(5,1)=5 P(5,2)=20 P(5,3)=60 P(5,4)=120 P(5,5)=120
P(6,1)=6 P(6,2)=30 P(6,3)=120 P(6,4)=360 P(6,5)=720 P(6,6)=720
P(7,1)=7 P(7,2)=42 P(7,3)=210 P(7,4)=840 P(7,5)=2520 P(7,6)=5040 P(7,7)=5040
P(8,1)=8 P(8,2)=56 P(8,3)=336 P(8,4)=1680 P(8,5)=6720 P(8,6)=20160 P(8,7)=40320 P(8,8)=40320
P(9,1)=9 P(9,2)=72 P(9,3)=504 P(9,4)=3024 P(9,5)=15120 P(9,6)=60480 P(9,7)=181440 P(9,8)=362880 P(9,9)=362880
P(10,1)=10 P(10,2)=90 P(10,3)=720 P(10,4)=5040 P(10,5)=30240 P(10,6)=151200 P(10,7)=604800 P(10,8)=1814400 P(10,9)=3628800 P(10,10)=3628800
P(11,1)=11 P(11,2)=110 P(11,3)=990 P(11,4)=7920 P(11,5)=55440 P(11,6)=332640 P(11,7)=1663200 P(11,8)=6652800 P(11,9)=19958400 P(11,10)=39916800 P(11,11)=39916800
P(12,1)=12 P(12,2)=132 P(12,3)=1320 P(12,4)=11880 P(12,5)=95040 P(12,6)=665280 P(12,7)=3991680 P(12,8)=19958400 P(12,9)=79833600 P(12,10)=239500800 P(12,11)=479001600 P(12,12)=479001600
-- Combinations from 10 to 60
 
C(10,1)=10 C(10,3)=120 C(10,5)=252 C(10,7)=120 C(10,9)=10
C(20,1)=20 C(20,5)=15504 C(20,9)=167960 C(20,13)=77520 C(20,17)=1140
C(30,1)=30 C(30,7)=2035800 C(30,13)=119759850 C(30,19)=54627300 C(30,25)=142506
C(40,1)=40 C(40,9)=273438880 C(40,17)=88732378800 C(40,25)=40225345056 C(40,33)=18643560
C(50,1)=50 C(50,11)=37353738800 C(50,21)=67327446062800 C(50,31)=30405943383200 C(50,41)=2505433700
C(60,1)=60 C(60,13)=5166863427600 C(60,25)=51915437974328292 C(60,37)=23385332420868600 C(60,49)=342700125300
 
-- Permutations from 5000 to 15000
 
P(5000,10)=9,67807348145655E+36 P(5000,30)=8,53575581200676E+110 P(5000,50)=6,94616656703754E+184 P(5000,70)=5,21383580146195E+258
P(10000,10)=9,95508690556325E+39 P(10000,30)=9,57391540294832E+119 P(10000,50)=8,84526658067387E+199 P(10000,70)=7,850079552152E+279
P(15000,10)=5,74922667554068E+41 P(15000,30)=1,86266591363916E+125 P(15000,50)=5,87565776023335E+208 P(15000,70)=1,80450662858719E+292
 
-- Combinations from 200 to 1000
 
C(200,20)=1613587787967350073386147640 C(200,40)=721126811024990370 C(200,60)=286107190317772000463240955 C(200,80)=900482 C(200,100)=478205104
C(400,20)=3558235073 C(400,40)=130321 C(400,60)=74780600187861332802765 C(400,80)=9521248771125 C(400,100)=447355513982663594791392
C(600,20)=2801445153584 C(600,40)=266319106596345 C(600,60)=14409368913 C(600,80)=271441 C(600,100)=52868467287780595308
C(800,20)=1925279023672620 C(800,40)=23121069591511231041 C(800,60)=18702067923763447158 C(800,80)=1193559552292625 C(800,100)=172727802
C(1000,20)=1239329180287869852 C(1000,40)=1937726921514640866484017 C(1000,60)=149470629867337347460963500 C(1000,80)=1269150275532146867313740 C(1000,100)=10088410532027029794548
 
=={{header|Maple}}==
Anonymous user