File: //usr/share/ri/3.0.0/system/Array/repeated_permutation-i.ri
U:RDoc::AnyMethod[iI"repeated_permutation:ETI"Array#repeated_permutation;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"]Calls the block with each repeated permutation of length +n+ of the elements of +self+; ;TI"$each permutation is an \Array; ;TI"Dreturns +self+. The order of the permutations 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 permutation of the elements of +self+. ;TI"9The number of permutations is <tt>self.size**n</tt>.;T@o;
; [I"
+n+ = 1:;To:RDoc::Markup::Verbatim; [I"a = [0, 1, 2]
;TI">a.repeated_permutation(1) {|permutation| p permutation }
;T:@format0o;
; [I"Output:;To;; [I" [0]
;TI" [1]
;TI" [2]
;T;
0o;
; [I"
+n+ = 2:;To;; [I">a.repeated_permutation(2) {|permutation| p permutation }
;T;
0o;
; [I"Output:;To;; [I"[0, 0]
;TI"[0, 1]
;TI"[0, 2]
;TI"[1, 0]
;TI"[1, 1]
;TI"[1, 2]
;TI"[2, 0]
;TI"[2, 1]
;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_permutation(-1) {|permutation| fail 'Cannot happen' }
;T;
0o;
; [I"1Returns a new \Enumerator if no block given:;To;; [I"a = [0, 1, 2]
;TI"La.repeated_permutation(2) # => #<Enumerator: [0, 1, 2]:permutation(2)>
;T;
0o;
; [I"LUsing Enumerators, it's convenient to show the permutations and counts ;TI"for some values of +n+:;To;; [I"#e = a.repeated_permutation(0)
;TI"e.size # => 1
;TI"e.to_a # => [[]]
;TI"#e = a.repeated_permutation(1)
;TI"e.size # => 3
;TI"!e.to_a # => [[0], [1], [2]]
;TI"#e = a.repeated_permutation(2)
;TI"e.size # => 9
;TI"Ye.to_a # => [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]];T;
0:
@fileI"array.c;T:0@omit_headings_from_table_of_contents_below0I"parray.repeated_permutation(n) {|permutation| ... } -> self
array.repeated_permutation(n) -> new_enumerator
;T0[ I" (p1);T@XFI"
Array;TcRDoc::NormalClass00