File: //usr/share/ri/3.0.0/system/Array/repeated_combination-i.ri
U:RDoc::AnyMethod[iI"repeated_combination:ETI"Array#repeated_combination;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"]Calls the block with each repeated combination of length +n+ of the elements of +self+; ;TI"$each combination is an \Array; ;TI"Dreturns +self+. The order of the combinations is indeterminate.;To:RDoc::Markup::BlankLine o;
; [I"\When a block and a positive \Integer argument +n+ are given, calls the block with each ;TI"?+n+-tuple repeated combination of the elements of +self+. ;TI"9The number of combinations is <tt>(n+1)(n+2)/2</tt>.;T@o;
; [I"
+n+ = 1:;To:RDoc::Markup::Verbatim; [I"a = [0, 1, 2]
;TI">a.repeated_combination(1) {|combination| p combination }
;T:@format0o;
; [I"Output:;To;; [I" [0]
;TI" [1]
;TI" [2]
;T;
0o;
; [I"
+n+ = 2:;To;; [I">a.repeated_combination(2) {|combination| p combination }
;T;
0o;
; [I"Output:;To;; [I"[0, 0]
;TI"[0, 1]
;TI"[0, 2]
;TI"[1, 1]
;TI"[1, 2]
;TI"[2, 2]
;T;
0o;
; [I"?If +n+ is zero, calls the block once with an empty \Array.;T@o;
; [I"1If +n+ is negative, does not call the block:;To;; [I"Fa.repeated_combination(-1) {|combination| fail 'Cannot happen' }
;T;
0o;
; [I"1Returns a new \Enumerator if no block given:;To;; [I"a = [0, 1, 2]
;TI"La.repeated_combination(2) # => #<Enumerator: [0, 1, 2]:combination(2)>
;T;
0o;
; [I"LUsing Enumerators, it's convenient to show the combinations and counts ;TI"for some values of +n+:;To;; [I"#e = a.repeated_combination(0)
;TI"e.size # => 1
;TI"e.to_a # => [[]]
;TI"#e = a.repeated_combination(1)
;TI"e.size # => 3
;TI"!e.to_a # => [[0], [1], [2]]
;TI"#e = a.repeated_combination(2)
;TI"e.size # => 6
;TI"Ae.to_a # => [[0, 0], [0, 1], [0, 2], [1, 1], [1, 2], [2, 2]];T;
0:
@fileI"array.c;T:0@omit_headings_from_table_of_contents_below0I"parray.repeated_combination(n) {|combination| ... } -> self
array.repeated_combination(n) -> new_enumerator
;T0[ I" (p1);T@UFI"
Array;TcRDoc::NormalClass00