キーワード
- choice (1)
- combination (6)
- pack (3)
- permutation (6)
-
repeated
_ combination (4) -
repeated
_ permutation (4) - sample (4)
-
to
_ ary (3) -
to
_ ptr (2)
検索結果
先頭5件
-
Array
# to _ a -> Array (18102) -
self を返します。ただし、Array のサブクラスのインスタンスに対して呼ばれた時は、 自身を Array に変換したものを返します。
...self を返します。ただし、Array のサブクラスのインスタンスに対して呼ばれた時は、
自身を Array に変換したものを返します。... -
Array
# to _ ary -> self (6101) -
self をそのまま返します。
self をそのまま返します。 -
Array
# combination(n) -> Enumerable :: Enumerator (37) -
サイズ n の組み合わせをすべて生成し、それを引数としてブロックを実行します。
...1).to_a #=> [[1],[2],[3],[4]]
a.combination(2).to_a #=> [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
a.combination(3).to_a #=> [[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
a.combination(4).to_a #=> [[1,2,3,4]]
a.combination(0).to_a #=> [[]]: one combination of length 0
a.combination(5).to_a......#=> [] : no combinations of length 5
@see Array#permutation... -
Array
# combination(n) -> Enumerator (37) -
サイズ n の組み合わせをすべて生成し、それを引数としてブロックを実行します。
...1).to_a #=> [[1],[2],[3],[4]]
a.combination(2).to_a #=> [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
a.combination(3).to_a #=> [[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
a.combination(4).to_a #=> [[1,2,3,4]]
a.combination(0).to_a #=> [[]]: one combination of length 0
a.combination(5).to_a......#=> [] : no combinations of length 5
@see Array#permutation, Array#repeated_combination... -
Array
# combination(n) {|c| block } -> Array (37) -
サイズ n の組み合わせをすべて生成し、それを引数としてブロックを実行します。
...1).to_a #=> [[1],[2],[3],[4]]
a.combination(2).to_a #=> [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
a.combination(3).to_a #=> [[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
a.combination(4).to_a #=> [[1,2,3,4]]
a.combination(0).to_a #=> [[]]: one combination of length 0
a.combination(5).to_a......#=> [] : no combinations of length 5
@see Array#permutation......#=> [] : no combinations of length 5
@see Array#permutation, Array#repeated_combination... -
Array
# permutation(n) -> Enumerable :: Enumerator (31) -
サイズ n の順列をすべて生成し,それを引数としてブロックを実行します。
...a.permutation(1).to_a #=> [[1],[2],[3]]
a.permutation(2).to_a #=> [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]]
a.permutation(3).to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
a.permutation(0).to_a #=> [[]]: one permutation of length 0
a.permutation(4).to_a #=> [] : no per......mutations of length 4
@see Array#combination... -
Array
# permutation(n) -> Enumerator (31) -
サイズ n の順列をすべて生成し,それを引数としてブロックを実行します。
...a.permutation(1).to_a #=> [[1],[2],[3]]
a.permutation(2).to_a #=> [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]]
a.permutation(3).to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
a.permutation(0).to_a #=> [[]]: one permutation of length 0
a.permutation(4).to_a #=> [] : no per......mutations of length 4
@see Array#combination, Array#repeated_permutation... -
Array
# permutation(n) { |p| block } -> Array (31) -
サイズ n の順列をすべて生成し,それを引数としてブロックを実行します。
...a.permutation(1).to_a #=> [[1],[2],[3]]
a.permutation(2).to_a #=> [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]]
a.permutation(3).to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
a.permutation(0).to_a #=> [[]]: one permutation of length 0
a.permutation(4).to_a #=> [] : no per......mutations of length 4
@see Array#combination......mutations of length 4
@see Array#combination, Array#repeated_permutation... -
Array
# repeated _ combination(n) -> Enumerator (31) -
サイズ n の重複組み合わせをすべて生成し、それを引数としてブロックを実行 します。
...る配列のサイズ。
例:
a = [1, 2, 3]
a.repeated_combination(1).to_a #=> [[1], [2], [3]]
a.repeated_combination(2).to_a #=> [[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]]
a.repeated_combination(3).to_a #=> [[1,1,1],[1,1,2],[1,1,3],[1,2,2],[1,2,3],......# [1,1,3,3],[1,2,2,2],[1,2,2,3],[1,2,3,3],[1,3,3,3],
# [2,2,2,2],[2,2,2,3],[2,2,3,3],[2,3,3,3],[3,3,3,3]]
a.repeated_combination(0).to_a #=> [[]] # one combination of length 0
@see Array#repeated_permutation, Array#combination... -
Array
# repeated _ combination(n) { |c| . . . } -> Array (31) -
サイズ n の重複組み合わせをすべて生成し、それを引数としてブロックを実行 します。
...る配列のサイズ。
例:
a = [1, 2, 3]
a.repeated_combination(1).to_a #=> [[1], [2], [3]]
a.repeated_combination(2).to_a #=> [[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]]
a.repeated_combination(3).to_a #=> [[1,1,1],[1,1,2],[1,1,3],[1,2,2],[1,2,3],......# [1,1,3,3],[1,2,2,2],[1,2,2,3],[1,2,3,3],[1,3,3,3],
# [2,2,2,2],[2,2,2,3],[2,2,3,3],[2,3,3,3],[3,3,3,3]]
a.repeated_combination(0).to_a #=> [[]] # one combination of length 0
@see Array#repeated_permutation, Array#combination... -
Array
# repeated _ permutation(n) -> Enumerator (25) -
サイズ n の重複順列をすべて生成し,それを引数としてブロックを実行します。
..._permutation(1).to_a #=> [[1], [2]]
a.repeated_permutation(2).to_a #=> [[1,1],[1,2],[2,1],[2,2]]
a.repeated_permutation(3).to_a #=> [[1,1,1],[1,1,2],[1,2,1],[1,2,2],
# [2,1,1],[2,1,2],[2,2,1],[2,2,2]]
a.repeated_permutation(0).to_a #=> [[]] # on......e permutation of length 0
@see Array#repeated_combination, Array#permutation... -
Array
# repeated _ permutation(n) { |p| . . . } -> Array (25) -
サイズ n の重複順列をすべて生成し,それを引数としてブロックを実行します。
..._permutation(1).to_a #=> [[1], [2]]
a.repeated_permutation(2).to_a #=> [[1,1],[1,2],[2,1],[2,2]]
a.repeated_permutation(3).to_a #=> [[1,1,1],[1,1,2],[1,2,1],[1,2,2],
# [2,1,1],[2,1,2],[2,2,1],[2,2,2]]
a.repeated_permutation(0).to_a #=> [[]] # on......e permutation of length 0
@see Array#repeated_combination, Array#permutation... -
Array
# choice -> object (7) -
配列の要素を1個ランダムに選んで返します。
...このメソッドは Ruby 1.8.7 と Ruby 1.9.0 にしか存在しないメソッドです。
Ruby 1.8.8 以降では Array#sample を使ってください。
例:
a = (1..10).to_a
p a.choice #=> 9
p a.choice #=> 10
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]... -
Array
# pack(template) -> String (7) -
配列の内容を template で指定された文字列にしたがって、 バイナリとしてパックした文字列を返します。
...template 自身のバイナリとしてパックするためのテンプレートを文字列で指定します。
以下にあげるものは、Array#pack、String#unpack
のテンプレート文字の一覧です。テンプレート文字は後に「長さ」を表す数字
を続けること......nt16_t
S: uint16_t
l: int32_t
L: uint32_t
//}
==== 各テンプレート文字の説明
説明中、Array#pack と String#unpack で違いのあるものは `/' で区切って
「Array#pack の説明 / String#unpack の説明」としています。
: a
ASCII文字列(null文字を詰......".unpack('ccxxcc') # => [82, 117, 98, 121]
//}
: Hexダンプを数値の配列に変換する例
//emlist{
"61 62 63 64 65 66".delete(' ').to_a.pack('H*').unpack('C*')
# => [97, 98, 99, 100, 101, 102]
"61 62 63 64 65 66".split.collect {|c| c.hex}
# => [97, 98, 99, 100, 101, 102... -
Array
# sample -> object (7) -
配列の要素を1個(引数を指定した場合は n 個)ランダムに選んで返します。
...の場合、無引数の場合は nil を、個数を指定した場合は空配列を返します。
srand()が有効です。
例:
a = (1..10).to_a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]... -
Array
# sample(n) -> Array (7) -
配列の要素を1個(引数を指定した場合は n 個)ランダムに選んで返します。
...の場合、無引数の場合は nil を、個数を指定した場合は空配列を返します。
srand()が有効です。
例:
a = (1..10).to_a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]... -
Array
# to _ ptr -> nil | DL :: PtrData (7) -
自身の各要素を指すポインタの配列を生成し、それへのポインタ DL::PtrData を返します。 この返り値には、DL::FREE が free 関数としてセットされています。 自身の長さが 0 なら nil を返します。
...スが String である場合、各要素は複製されます。
require 'dl/import'
ptr = ['a', 'b', 'c'].to_ptr
p ptr.size #=> 12
p ptr.to_a('P').map{|s| s.to_s } #=> ["a", "b", "c"]
@param type self の要素の型を文字で指定します。DL の型指定子の項を参照して下... -
Array
# to _ ptr(type) -> nil | DL :: PtrData (7) -
自身の各要素を指すポインタの配列を生成し、それへのポインタ DL::PtrData を返します。 この返り値には、DL::FREE が free 関数としてセットされています。 自身の長さが 0 なら nil を返します。
...スが String である場合、各要素は複製されます。
require 'dl/import'
ptr = ['a', 'b', 'c'].to_ptr
p ptr.size #=> 12
p ptr.to_a('P').map{|s| s.to_s } #=> ["a", "b", "c"]
@param type self の要素の型を文字で指定します。DL の型指定子の項を参照して下...
