Combinations with repetitions: Difference between revisions

→‎Concise recursive: Changed to Wren S/H
imported>Rowsety Moid
(Add Acornsoft Lisp)
(→‎Concise recursive: Changed to Wren S/H)
 
(2 intermediate revisions by the same user not shown)
Line 4,037:
{{trans|Go}}
Produces results in no particular order.
<syntaxhighlight lang="ecmascriptwren">var combrepCombrep //= recursiveFn.new { |n, lst|
combrep = Fn.new { |n, lst|
if (n == 0 ) return [[]]
if (lst.count == 0) return []
var r = combrepCombrep.call(n, lst[1..-1])
for (x in combrepCombrep.call(n-1, lst)) {
var y = x.toList
y.add(lst[0])
Line 4,050 ⟶ 4,049:
}
 
System.print(combrepCombrep.call(2, ["iced", "jam", "plain"]))
System.print(combrepCombrep.call(3, (1..10).toList).count)</syntaxhighlight>
 
{{out}}
Line 4,058 ⟶ 4,057:
220
</pre>
 
===Library based===
{{libheader|Wren-seq}}
{{libheader|Wren-perm}}
Produces results in lexicographic order.
<syntaxhighlight lang="ecmascriptwren">import "./seq" for Lst
import "./perm" for Comb
 
9,476

edits