2016年7月23日土曜日

160723(3)

Ruby


An 型フリーズパターンと多角形の三角形分割(2)

An 型のフリーズパターンには、何通りの異なる斜めの列があるかは
次のようにして求められる。

正多角形の三角形分割において、回転移動で重ならないものを考え、
その三角形分割からAn 型のフリーズパターンを構成すればよい。

def A1(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
  a_ary.uniq!
end

p 3
a = []
[[1, 1]].each{|i|
  a += A1(i)
  p ""
}
p "#{a.uniq.size} = 1"
p ""
p 4
a = []
[[1, 1, 1]].each{|i|
  a += A1(i)
  p ""
}
p "#{a.uniq.size} = 2"
p ""
p 5
a = []
[[1, 1, 1, 1]].each{|i|
  a += A1(i)
  p ""
}
p "#{a.uniq.size} = 5"
p ""
p 6
a = []
[[1, 1, 1, 1, 1],
 [1, 3, 2, 1, 1],
 [1, 1, 2, 3, 1],
 [1, 1, 2, 1, 1]].each{|i|
  a += A1(i)
  p ""
}
p "#{a.uniq.size} = 6 + 3 + 3 + 2"
p ""
p 7
a = []
[[1, 1, 1, 1, 1, 1],
 [1, 4, 3, 2, 1, 1],
 [1, 1, 2, 3, 4, 1],
 [1, 1, 2, 1, 1, 1],
 [1, 1, 1, 2, 1, 1],
 [1, 2, 1, 1, 2, 1]].each{|i|
  a += A1(i)
  p ""
}
p "#{a.uniq.size} = 7 + 7 + 7 + 7 + 7 + 7"

出力結果
3
[1, 1]
[1, 1]
""
"1 = 1"
""
4
[1, 1, 1]
[1, 2, 1]
[1, 1, 1]
""
"2 = 2"
""
5
[1, 1, 1, 1]
[1, 3, 2, 1]
[1, 1, 2, 1]
[1, 2, 1, 1]
[1, 2, 3, 1]
[1, 1, 1, 1]
""
"5 = 5"
""
6
[1, 1, 1, 1, 1]
[1, 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