with(combinat); with(combstruct); read "C:/Users/Wieder/Documents/EDV/Maple/Number_of_k_Combinations.mpl"; Test_Number_of_ordered_k_Combinations := proc(n::integer) local Liste,k,cnt,Result; Liste:=[seq(seq(i,j=1..n),i=1..n)]; cnt:=0; for k from 0 to nops(Liste) do gc(); cnt:=cnt+1; Result[cnt]:=Number_of_ordered_k_Combinations(Liste,k); printf("\n %g %g %g",cnt,k,Result[cnt]); end do; print(seq(Result[i],i=1..cnt)); end proc; Number_of_ordered_k_Combinations := proc(Liste::list,k::integer) # Begonnen am: 28.12.2013 # Letzte Aenderung am: 28.12.2013 # thomas.wieder@t-online.de local iverbose,ListMultiset,Selection,SelectionList,NextPermutation, PermutationList,Result; # Set iverbose = 1 for debugging, else set iverbose = 0. iverbose:=0; try if iverbose = 1 then print("----"); print("List, k:",Liste,k); end if; Result := 0; SelectionList := iterstructs(Combination(Liste),size=k); while not finished(SelectionList) do Selection:=nextstruct(SelectionList); PermutationList := iterstructs(Permutation(Selection)); while not finished(PermutationList) do NextPermutation := nextstruct(PermutationList); Result := Result + 1; if iverbose = 1 then print("Selection, Permutation:",Selection,NextPermutation); end if; # End of loop over PermutationList. end do; # End of loop over SelectionList. end do; return Result; catch: printf("Number_of_ordered_k_Combinations: Something went wrong: %q\n",lastexception); error end try; end proc;