def somos(ary, k)
s = 0
for i in (1..k / 2)
s += ary[i] * ary[k - i]
end
s /= ary[0]
end
def somos_sequence(k, n)
ary = Array.new(k, 1)
list = ary
i = k - 1
while i < n
ary0 = ary[1..-1]
j = somos(ary, k)
ary = ary0.push(j)
list.push(j)
i += 1
end
return list
end
list = somos_sequence(4, 23)
# OEIS A006720のデータ
list0 =
[1,1,1,1,2,3,7,23,59,314,1529,8209,83313,620297,
7869898,126742987,1687054711,47301104551,
1123424582771,32606721084786,1662315215971057,
61958046554226593,4257998884448335457,
334806306946199122193]
# 一致の確認
p list == list0
list = somos_sequence(5, 26)
# OEIS A00671のデータ
list0 =
[1,1,1,1,1,2,3,5,11,37,83,274,1217,6161,22833,
165713,1249441,9434290,68570323,1013908933,
11548470571,142844426789,2279343327171,
57760865728994,979023970244321,23510036246274433,
771025645214210753]
# 一致の確認
p list == list0
list = somos_sequence(6, 25)
# OEIS A00672のデータ
list0 =
[1,1,1,1,1,1,3,5,9,23,75,421,1103,5047,41783,
281527,2534423,14161887,232663909,3988834875,
45788778247,805144998681,14980361322965,
620933643034787,16379818848380849,
369622905371172929]
# 一致の確認
p list == list0
list = somos_sequence(7, 28)
# OEIS A00673のデータ
list0 =
[1,1,1,1,1,1,1,3,5,9,17,41,137,769,1925,7203,
34081,227321,1737001,14736001,63232441,702617001,
8873580481,122337693603,1705473647525,
22511386506929,251582370867257,9254211194697641,
215321535159114017]
# 一致の確認
p list == list0