| |
|
|
 p.specht
 | Ein aus Prof. D. Knuth's 'Algorithm X-7' entwickeltes Teil verwendet nun Procedures statt GOTO sowie INC und DEC statt arithmetische Indexberechnung, was die Sache langsam auch hinsichtlich Geschwindigkeit brauchbar macht.
WindowTitle "Kombinationen-Generator für k aus N Elementen ohne Wiederholung"
'(CL) CopyLeft 2015-09 by P.Specht, Wien; ohne jegliche Gewähr!
WindowStyle 24:Font 2
Declare j%,s%,b%[],n%,dflg%'...Globale Variablen
Main:
Cls rgb(170,255,220)
print "\n 0 für aufsteigende, 1 für absteigende Lexikalordnung?: ";:input dflg%
print "\n N = ";:input n%:print " k = ";:input s%
SetSize b%[],s%:WhileLoop s%:b%[&Loop]=&Loop+n%-s%-1:EndWhile :j%=1
COMBN'Aufruf des Generators, der dann Kombinationen b%[1.sz%] an
'DoSomethingUseful' liefert
print "\n OK. ";:WaitInput
Goto "Main"
PROC COMBN
REPEAT
DoSomethingUseful'with b&[1..sz&]
case j%>s%:BREAK
b%[j%]=b%[j%]-1:if b%[j%]<j%:inc j%:CONTINUE:endif
:while j%>1:b%[j%-1]=b%[j%]-1:dec j%:endwhile
UNTIL 0
ENDPROC
proc DoSomethingUseful'...hier z.B. Anzeige der einzelnen Elemente:
Whileloop s%,1,-1
if dflg%=0
print int(n%-1-b%[&Loop]),'increasing
else
print b%[&Loop],'decreasing
endif
EndWhile
print " ";
case %pos>(60-s%):print
if %csrlin>30:print "...":WaitInput:cls:endif
endproc
|
|
|
| XProfan 11Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'... | 19.05.2021 ▲ |
|
|
|