Permutations with repetitions: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (added Arturo) |
(Added XPL0 example.) |
||
Line 2,830: | Line 2,830: | ||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
{{out}} |
|||
<pre> |
|||
[A, A, A] |
|||
[B, A, A] |
|||
[C, A, A] |
|||
[D, A, A] |
|||
[A, B, A] |
|||
[B, B, A] |
|||
[C, B, A] |
|||
[D, B, A] |
|||
[A, C, A] |
|||
[B, C, A] |
|||
</pre> |
|||
=={{header|XPL0}}== |
|||
{{trans|Wren}} |
|||
<syntaxhighlight lang "XPL0">func Decide(PC); |
|||
\Terminate when first two characters of permutation are 'B' and 'C' respectively |
|||
int PC; |
|||
return PC(0)=^B & PC(1)=^C; |
|||
def N=3, K=4; |
|||
int Values, PN(N), PC(N), I, X; |
|||
[Values:= [^A, ^B, ^C, ^D]; |
|||
for I:= 0 to N-1 do PN(I):= 0; |
|||
loop [for I:= 0 to N-1 do |
|||
[X:= PN(I); |
|||
PC(I):= Values(X); |
|||
]; |
|||
ChOut(0, ^[); \show progress |
|||
for I:= 0 to N-1 do |
|||
[if I # 0 then Text(0, ", "); ChOut(0, PC(I))]; |
|||
ChOut(0, ^]); CrLf(0); |
|||
\pass to deciding function |
|||
if Decide(PC) then return; \terminate early |
|||
I:= 0; \increment permutation number |
|||
loop [PN(I):= PN(I)+1; |
|||
if PN(I) < K then quit; |
|||
PN(I):= 0; |
|||
I:= I+1; |
|||
if I = N then return; \all permutations generated |
|||
]; |
|||
]; |
|||
]</syntaxhighlight> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |