Topswops(3)
1が一番上にくるまでの回数が最も多い並べ方を調べてみた。
def conway2(n)
ary = []
max = 0
(1..n).to_a.permutation{|c|
a = c.clone
i = 0
while (c0 = c[0]) > 1
c[0..c0 - 1] = c[0..c0 - 1].reverse
i += 1
end
if i > max
ary = [a]
max = i
elsif i == max
ary << a
else
end
}
[max, ary]
end
(1..11).each{|i| p conway2(i)}
出力結果
[0, [[1]]]
[1, [[2, 1]]]
[2, [[2, 3, 1], [3, 1, 2]]]
[4, [[2, 4, 1, 3], [3, 1, 4, 2]]]
[7, [[3, 1, 4, 5, 2]]]
[10, [[3, 6, 5, 1, 4, 2], [4, 1, 5, 2, 6, 3], [4, 1, 6, 5, 2, 3], [4, 5, 6, 2, 1, 3], [5, 6, 4, 1, 3, 2]]]
[16, [[3, 1, 4, 6, 7, 5, 2], [4, 7, 6, 2, 1, 5, 3]]]
[22, [[6, 1, 5, 7, 8, 3, 2, 4]]]
[30, [[6, 1, 5, 9, 7, 2, 8, 3, 4]]]
[38, [[5, 9, 1, 8, 6, 2, 10, 4, 7, 3]]]
[51, [[4, 9, 11, 6, 10, 7, 8, 2, 1, 3, 5]]]
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。