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