combinations_with_repetitions.sf 349 B

123456789101112
  1. #!/usr/bin/ruby
  2. func p (n, a, l) { n>0 ? (l.range.map{p(n-1, a+[l[_]], l.slice(_))}) : a };
  3. func f (n) { n>0 ? (n * f(n - 1)) : 1 };
  4. func n (n, m) { f(n + m - 1) / f(n) / f(m - 1) };
  5. p(2, [], %w(iced jam plain)).each { |a|
  6. say a.map{|pair| pair.join(" ")}.join("\n");
  7. }
  8. printf("\nThere are %d ways to pick 7 out of 10\n", n(7, 10));