Anonymous user
Combinations with repetitions: Difference between revisions
→{{header|Ruby}}: add extra credit
(jq) |
(→{{header|Ruby}}: add extra credit) |
||
Line 1,468:
=={{header|Ruby}}==
<lang ruby>possible_doughnuts = ['iced', 'jam', 'plain'].repeated_combination(2)▼
▲possible_doughnuts = ['iced', 'jam', 'plain'].repeated_combination(2)
puts "There are #{possible_doughnuts.count} possible doughnuts:"
possible_doughnuts.each{|doughnut_combi| puts doughnut_combi.join(' and ')}
# Extra credit
possible_doughnuts = [*1..10].repeated_combination(3)
puts "", "#{possible_doughnuts.count} ways to order 3 donuts given 10 types"</lang>
{{out}}
<pre>
There are 6 possible doughnuts:
Line 1,484 ⟶ 1,485:
jam and plain
plain and plain
220 ways to order 3 donuts given 10 types
</pre>
|