Combinations with repetitions: Difference between revisions

Content added Content deleted
imported>Rowsety Moid
(Add Acornsoft Lisp)
m (→‎Concise recursive: Minor tidy)
Line 4,037: Line 4,037:
{{trans|Go}}
{{trans|Go}}
Produces results in no particular order.
Produces results in no particular order.
<syntaxhighlight lang="ecmascript">var combrep // recursive
<syntaxhighlight lang="ecmascript">var Combrep = Fn.new { |n, lst|
combrep = Fn.new { |n, lst|
if (n == 0 ) return [[]]
if (n == 0 ) return [[]]
if (lst.count == 0) return []
if (lst.count == 0) return []
var r = combrep.call(n, lst[1..-1])
var r = Combrep.call(n, lst[1..-1])
for (x in combrep.call(n-1, lst)) {
for (x in Combrep.call(n-1, lst)) {
var y = x.toList
var y = x.toList
y.add(lst[0])
y.add(lst[0])
Line 4,050: Line 4,049:
}
}


System.print(combrep.call(2, ["iced", "jam", "plain"]))
System.print(Combrep.call(2, ["iced", "jam", "plain"]))
System.print(combrep.call(3, (1..10).toList).count)</syntaxhighlight>
System.print(Combrep.call(3, (1..10).toList).count)</syntaxhighlight>


{{out}}
{{out}}
Line 4,058: Line 4,057:
220
220
</pre>
</pre>

===Library based===
===Library based===
{{libheader|Wren-seq}}
{{libheader|Wren-seq}}