Combinations with repetitions: Difference between revisions
m
→{{header|Sidef}}: updated code
m (→{{header|Sidef}}: updated code) |
|||
Line 2,899:
=={{header|Sidef}}==
{{trans|Perl}}
<lang ruby>func
p(2, [], %w(iced jam plain)).each { |a|▼
say a.map{|pair| pair.join(" ")}.join("\n");▼
}
printf("\nThere are %d ways to pick 7 out of 10\n", n(7, 10));</lang>▼
}</lang>
Also built-in:
<lang ruby>%w(iced jam plain).combinations_with_repetition(2, {|*a|
say a.join(' ')
})</lang>
{{out}}
Line 2,917 ⟶ 2,921:
jam plain
plain plain
</pre>
Efficient count of the total number of combinations with repetition:
There are 11440 ways to pick 7 out of 10▼
<lang ruby>func cwr_count (n, m) { binomial(n + m - 1, m) }
{{out}}
<pre>
▲There are 11440 ways to pick 7 out of 10 with repetition
</pre>
|