Combinations with repetitions: Difference between revisions

* {{header|VBScript}} */ Section added
(* {{header|VBScript}} */ Section added)
Line 3,250:
220)
</pre>
 
=={{header|VBScript}}==
<lang vb>' Combinations with repetitions - iterative - VBScript
 
Sub printc(vi,n,vs)
Dim i, w
For i=0 To n-1
w=w &" "& vs(vi(i))
Next 'i
Wscript.Echo w
End Sub
 
Sub combine(flavors, draws, xitem, tell)
Dim n, i, j
ReDim v(draws)
If tell Then Wscript.Echo "list of cwr("& flavors &","& draws &") :"
Do While True
For i=0 To draws-1
If v(i)>flavors-1 Then
v(i+1)=v(i+1)+1
For j=i To 0 Step -1
v(j)=v(i+1)
Next 'j
End If
Next 'i
If v(draws)>0 Then Exit Do
n=n+1
If tell Then Call printc(v, draws, xitem)
v(0)=v(0)+1
Loop
Wscript.Echo "cwr("& flavors &","& draws &")="&n
End Sub
 
items=Array( "iced", "jam", "plain" )
combine 3, 2, items, True
combine 10, 3, , False
combine 10, 7, , False
combine 10, 9, , False </lang>
{{out}}
<pre>
list of cwr(3,2) :
iced iced
jam iced
plain iced
jam jam
plain jam
plain plain
cwr(3,2)=6
cwr(10,3)=220
cwr(10,7)=11440
cwr(10,9)=48620
</pre>
 
 
=={{header|XPL0}}==
1,392

edits