Ruby
Dn 型フリーズパターン
偶奇の違いを確認してみた。
def D(ary)
m = ary.size
a_ary = [ary]
p a_ary[0]
i = 0
while i == 0 || a_ary[i] != ary
a_ary << Array.new(m, 1)
(m - 2).downto(3){|j| a_ary[i + 1][j] = (a_ary[i][j - 1] * a_ary[i + 1][j + 1] + 1) / a_ary[i][j]}
a_ary[i + 1][2] = (a_ary[i][0] * a_ary[i][1] * a_ary[i + 1][3] + 1) / a_ary[i][2]
a_ary[i + 1][1] = ( a_ary[i + 1][2] + 1) / a_ary[i][1]
a_ary[i + 1][0] = ( a_ary[i + 1][2] + 1) / a_ary[i][0]
p a_ary[i + 1]
i += 1
end
end
D([10, 5, 29, 8, 3, 1])
p ''
D([5, 10, 29, 8, 3, 1])
p ''
D([3, 6, 5, 2, 1])
p ''
D([6, 3, 5, 2, 1])
出力結果
[10, 5, 29, 8, 3, 1]
[2, 4, 19, 11, 3, 1]
[2, 1, 3, 7, 4, 1]
[1, 2, 1, 1, 2, 1]
[6, 3, 5, 2, 1, 1]
[5, 10, 29, 8, 3, 1]
[4, 2, 19, 11, 3, 1]
[1, 2, 3, 7, 4, 1]
[2, 1, 1, 1, 2, 1]
[3, 6, 5, 2, 1, 1]
[10, 5, 29, 8, 3, 1]
""
[5, 10, 29, 8, 3, 1]
[4, 2, 19, 11, 3, 1]
[1, 2, 3, 7, 4, 1]
[2, 1, 1, 1, 2, 1]
[3, 6, 5, 2, 1, 1]
[10, 5, 29, 8, 3, 1]
[2, 4, 19, 11, 3, 1]
[2, 1, 3, 7, 4, 1]
[1, 2, 1, 1, 2, 1]
[6, 3, 5, 2, 1, 1]
[5, 10, 29, 8, 3, 1]
""
[3, 6, 5, 2, 1]
[4, 2, 11, 3, 1]
[1, 2, 3, 4, 1]
[2, 1, 1, 1, 1]
[3, 6, 5, 2, 1]
""
[6, 3, 5, 2, 1]
[2, 4, 11, 3, 1]
[2, 1, 3, 4, 1]
[1, 2, 1, 1, 1]
[6, 3, 5, 2, 1]
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。