Anonymous user
Combinations and permutations: Difference between revisions
m
→{{header|REXX}}: changed some comments.
m (→{{header|REXX}}: added/changed whitespace and comments.) |
m (→{{header|REXX}}: changed some comments.) |
||
Line 1,168:
numeric digits 100 /*use 100 decimal digits of precision. */
do j=1 for 12
_=; do k=1
_=_ 'P('j","k')='perm(j,k)" " /*add an extra blank between numbers. */
end /*k*/
Line 1,175:
end /*j*/
say
do j=10 to 60 by 10
_=; do k= 1 to j by j%5
_=_ 'C('j","k')='comb(j,k)" " /*add an extra blank between numbers. */
end /*k*/
Line 1,184:
numeric digits 20 /*force floating point for big numbers.*/
do j=5 to 15000
_=; do k=1 to j for 5 by j%10
_=_ 'P('j","k')='perm(j,k)" " /*add an extra blank between numbers. */
end /*k*/
Line 1,191:
end /*j*/
say
do j=100 to 1000 by 100
_=; do k= 1 to j by j%5
_=_ 'C('j","k')='comb(j,k)" " /*add an extra blank between numbers. */
end /*k*/
Line 1,199:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────one─liner subroutines─────────────────────*/
perm: procedure;
.
!: procedure; parse arg x; !=1; do j=2 to x;
/*────────────────────────────────────────────────────────────────────────────*/
comb: procedure; parse arg x,y /*arguments: X things, Y at-a-time.*/
Line 1,207:
if x=y then return 1 /*X things are the same as chunk size.*/
if x-y<y then y=x-y /*switch things around for speed. */
call .
return _/!(y) /*just perform one last division. */</lang>
'''output'''
|