Ruby
A2n−1 型からBn 型への折り畳み
上下が対称なA2n−1 型の (Conway-Coxeter) フリーズパターンを作成するこ とによって、
Bn 型のフリーズパターンを構成できることを確かめてみた。
出力結果
[1, 2, 7, 12, 29, 17, 5, 3, 1]
[1, 1, 1, 3, 5, 12, 7, 2, 1]
[1, 3, 2, 1, 2, 3, 7, 4, 1]
[1, 2, 5, 3, 1, 1, 1, 2, 1]
[1, 4, 7, 17, 10, 3, 2, 1, 1]
[1, 2, 7, 12, 29, 17, 5, 3, 1]
""
[29, 17, 5, 3, 1]
[5, 12, 7, 2, 1]
[2, 3, 7, 4, 1]
[1, 1, 1, 2, 1]
[10, 3, 2, 1, 1]
[29, 17, 5, 3, 1]
def A(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(1){|j| a_ary[i + 1][j] = (a_ary[i][j - 1] * a_ary[i + 1][j + 1] + 1) / a_ary[i][j]}
p a_ary[i + 1]
i += 1
end
end
def B(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(1){|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][0] = (a_ary[i + 1][1] * a_ary[i + 1][1] + 1) / a_ary[i][0]
p a_ary[i + 1]
i += 1
end
end
A([1, 2, 7, 12, 29, 17, 5, 3, 1])
p ''
B([29, 17, 5, 3, 1])
出力結果
[1, 2, 7, 12, 29, 17, 5, 3, 1]
[1, 1, 1, 3, 5, 12, 7, 2, 1]
[1, 3, 2, 1, 2, 3, 7, 4, 1]
[1, 2, 5, 3, 1, 1, 1, 2, 1]
[1, 4, 7, 17, 10, 3, 2, 1, 1]
[1, 2, 7, 12, 29, 17, 5, 3, 1]
""
[29, 17, 5, 3, 1]
[5, 12, 7, 2, 1]
[2, 3, 7, 4, 1]
[1, 1, 1, 2, 1]
[10, 3, 2, 1, 1]
[29, 17, 5, 3, 1]
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。