| |
|
|
p.specht
| with the spending of Kombinationen the wide k from n Elementen is the slippy 'Algorithm T' angesagt; though have I it same combined with 'Algorithm X-7', sodaß one now optional aufsteigende (dflg%=0) or absteigende (dflg%=1) lexikalische Order dial can. on what The combined Indizes verweisen, remaining naturally you give over!
Window Title "Algorithm X-7 from D. Knuth´s TAOCP 7.2.1.3 p.36 Xercise 7"
' (D)2011/07 Demoware by P. woodpecker
' No warranties whatsoever. Use at your own risk!
' Improved by a decrease-flag (dflg%): 0 = increasing, nonzero = decreasing
var dflg%=0'decreasing order-flag off
Font 2
declare j%,s%,b%[],n%
Start:
CLS rgb(170,255,220)
print " Inc/Decreasing Combinations of k Elements out of N"
print " 0 for aufsteigende, 1 for absteigende Lexikalordnung?: ";:input dflg%
print " n = ";:input n%:print " k = ";:input s%
SetSize b%[],s%
s1:' Initialize
WhileLoop s%:b%[&Loop]=&Loop+n%-s%-1
EndWhile :j%=1
s2:' Show result ('Visit' = do something useful)
Whileloop s%,1,-1
if dflg%=0:print int(n%-1-b%[&Loop]);'increasing order
else :print b%[&Loop];'decreasing order
endif
EndWhile
case j%>s%:goto "Halt"' terminate if j>s
print ",";:case %pos>(60-s%): print
if %csrlin>20: WaitInput : cls : endif
s3:' Decrease b(j)
b%[j%]=b%[j%]-1
if b%[j%]<j%
j%=j%+1
goto "S2"
endif
s4:' Reset b%[j%-1]
while j%>1
b%[j%-1]=b%[j%]-1
j%=j%-1
endwhile
Goto "S2"
hold:
print:print " done. ";
WaitInput
Goto "Start"
END
|
|
|
| Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'... | 04/13/21 ▲ |
|
|
|