D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Array
/
Filename :
permutation-i.ri
back
Copy
U:RDoc::AnyMethod[iI"permutation:ETI"Array#permutation;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I";Iterates over permutations of the elements of +self+; ;TI"0the order of permutations is indeterminate.;To:RDoc::Markup::BlankLine o; ; [I"mWith a block and an in-range positive integer argument +count+ (<tt>0 < count <= self.size</tt>) given, ;TI"Fcalls the block with each permutation of +self+ of size +count+; ;TI"returns +self+:;T@o:RDoc::Markup::Verbatim; [I"a = [0, 1, 2] ;TI"perms = [] ;TI"1a.permutation(1) {|perm| perms.push(perm) } ;TI" perms # => [[0], [1], [2]] ;TI" ;TI"perms = [] ;TI"1a.permutation(2) {|perm| perms.push(perm) } ;TI"Aperms # => [[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1]] ;TI" ;TI"perms = [] ;TI"1a.permutation(3) {|perm| perms.push(perm) } ;TI"Sperms # => [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]] ;T:@format0o; ; [I"GWhen +count+ is zero, calls the block once with a new empty array:;T@o;; [I"perms = [] ;TI"1a.permutation(0) {|perm| perms.push(perm) } ;TI"perms # => [[]] ;T; 0o; ; [I"PWhen +count+ is out of range (negative or larger than <tt>self.size</tt>), ;TI"does not call the block:;T@o;; [I"=a.permutation(-1) {|permutation| fail 'Cannot happen' } ;TI"<a.permutation(4) {|permutation| fail 'Cannot happen' } ;T; 0o; ; [I"3With no block given, returns a new Enumerator.;T@o; ; [I"LRelated: {Methods for Iterating}[rdoc-ref:Array@Methods+for+Iterating].;T: @fileI"array.c;T:0@omit_headings_from_table_of_contents_below0I"rpermutation(count = self.size) {|permutation| ... } -> self permutation(count = self.size) -> new_enumerator ;T0[ I"(*args);T@9FI" Array;TcRDoc::NormalClass00