2020年4月1日水曜日

200401

Python


A007764 とA271507 の内訳

Graphillion を使って計算してみた。

from graphillion import GraphSet
import graphillion.tutorial as tl

def A333520(n):
    if n == 1: return [1]
    universe = tl.grid(n - 1, n - 1)
    GraphSet.set_universe(universe)
    start, goal = 1, n * n
    paths = GraphSet.paths(start, goal)
    return [paths.len(2 * (n - 1 + k)).len() for k in range((n - 1) ** 2 // 2 + 1)]

def A329633(n):
    if n == 1: return [1]
    universe = tl.grid(n - 1, n - 1)
    GraphSet.set_universe(universe)
    start, goal = 1, n
    paths = GraphSet.paths(start, goal)
    return [paths.len(n - 1 + 2 * k).len() for k in range(n * (n - 1) // 2 + 1)]

a_list = []
for n in range(1, 10):
    a = A333520(n)
    a_list.append(sum(a))
    print([n, a])
print(a_list)

a_list = []
for n in range(1, 10):
    a = A329633(n)
    a_list.append(sum(a))
    print([n, a])
print(a_list)

出力結果
[1, [1]]
[2, [2]]
[3, [6, 4, 2]]
[4, [20, 36, 48, 48, 32]]
[5, [70, 224, 510, 956, 1586, 2224, 2106, 732, 104]]
[6, [252, 1200, 3904, 10560, 25828, 58712, 121868, 217436, 300380, 280776, 170384, 61336, 10180]]
[7, [924, 5940, 25186, 88084, 277706, 821480, 2309402, 6140040, 15130410, 33339900, 62692432, 96096244, 116826664, 110195700, 78154858, 39287872, 12396758, 1879252, 111712]]
[8, [3432, 28028, 146584, 624340, 2377272, 8462820, 28776128, 94238536, 297191100, 896047312, 2546144660, 6680419996, 15815316056, 33077697996, 60178275856, 94178946072, 125506736172, 140596369668, 129855611460, 95988303604, 54346307964, 22183235872, 6043428540, 967772896, 67590888]]
[9, [12870, 128128, 797052, 3983816, 17629208, 72458528, 283712460, 1072443924, 3937918900, 14066778160, 48770325700, 163139663720, 521548222412, 1574551014304, 4432290159968, 11499012639224, 27239037773318, 58501384426476, 113288208212484, 196789936838036, 304802809328332, 417652572628088, 500928869596082, 518566360053936, 455147191259656, 331385170320868, 194939663325166, 89645976737872, 30824065740276, 7417611707528, 1120646287168, 87526550468, 2688307514]]
[1, 2, 12, 184, 8512, 1262816, 575780564, 789360053252, 3266598486981642]
[1, [1]]
[2, [1, 1]]
[3, [1, 3, 5, 2]]
[4, [1, 6, 16, 39, 61, 47, 8]]
[5, [1, 10, 40, 125, 400, 1048, 1905, 2372, 1839, 764, 86]]
[6, [1, 15, 85, 335, 1237, 4638, 15860, 44365, 99815, 181995, 262414, 285086, 218011, 104879, 26344, 1770]]
[7, [1, 21, 161, 791, 3361, 13952, 58070, 232243, 832142, 2593461, 7050363, 16792687, 34757775, 61408506, 90658299, 109096566, 103422092, 73555738, 36524442, 11331348, 1833648, 88418]]
[8, [1, 28, 280, 1694, 8289, 37953, 170838, 767788, 3393035, 14146880, 53986313, 187172584, 591447455, 1707679296, 4493518214, 10698808881, 22837317345, 43276246162, 72005361759, 103756776232, 127221992958, 129859297139, 107392360699, 69520076355, 33639644113, 11377703747, 2418924278, 267844566, 8934966]]
[9, [1, 36, 456, 3354, 18901, 95511, 463500, 2216686, 10567808, 50018095, 229837003, 1000613739, 4075412853, 15496037329, 55118028311, 183704714639, 573394187702, 1671186818906, 4528288476197, 11351266746427, 26189578078433, 55304540386554, 106197268433138, 183996474717841, 285023298502055, 390621776748810, 467942847317180, 483141430614882, 422762865315696, 307119589396008, 180479878973823, 82945534742174, 28476975005088, 6835995356060, 1034770138602, 82247277872, 2087813834]]
[1, 2, 11, 178, 8590, 1246850, 550254085, 741333619848, 3046540983075504]

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。