Project

General

Profile

Actions

Backport #3708

closed

Array#permutation がおかしな結果を返す

Added by akai (Shumpei Akai) over 13 years ago. Updated about 13 years ago.

Status:
Closed

Description

=begin
Array#permutationの結果に,配列に含まれていないはずの値が入っています

% ./ruby_head -e "p [0,1,2,3,4][1,4].permutation.to_a"
[[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1], [0, 3, 1, 2], [0, 3, 2, 1], [1, 0, 2, 3], [1, 0, 3, 2], [1, 2, 0, 3], [1, 2, 3, 0], [1, 3, 0, 2], [1, 3, 2, 0], [2, 0, 1, 3], [2, 0, 3, 1], [2, 1, 0, 3], [2, 1, 3, 0], [2, 3, 0, 1], [2, 3, 1, 0], [3, 0, 1, 2], [3, 0, 2, 1], [3, 1, 0, 2], [3, 1, 2, 0], [3, 2, 0, 1], [3, 2, 1, 0]]

[0,1,2,3,4][1,4] は [1, 2, 3, 4] なので0は含まれないはずです.

% ./ruby_head -e "p [0,1,2,3][1,3].permutation.to_a"
だと正しく動きます
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0