-
Notifications
You must be signed in to change notification settings - Fork 0
/
A351021+2.sage
53 lines (46 loc) · 1.75 KB
/
A351021+2.sage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/env sage
from itertools import count, permutations
from time import time
from datetime import datetime, timedelta
print("n: A351021(n) and A351022(n)")
print("0: 1 and 1")
primelist = []
def symmetrictoeplitz(entries): # Symmetric Toeplitz matrix whose top row is the provided list
N = len(entries) * 2 - 1
newentries = list(reversed(entries))[:-1] + list(entries)
d = (N + 1) // 2 # We are constructing a d-by-d matrix.
return [newentries[i:i+d] for i in range(d-1, d-1-d, -1)]
P = Primes()
inf = float('inf')
for n in count(1):
if len(primelist) == 0: primelist.append(P.first())
else: primelist.append(P.next(primelist[-1]))
minperm, maxperm, minmat, maxmat = +inf, -inf, 0, 0
fac = factorial(n)
starttime = time()
k = 0
for (k,row) in enumerate(permutations(primelist)):
if k % 1000 == 0 and k > 0:
ettc = float((time() - starttime) * (fac/k - 1.0)) # estimated time to completion
eta = datetime.isoformat(datetime.now() + timedelta(seconds=ettc), sep=' ', timespec='seconds')
print('\b'*160, "%d/%d = %0.5f%%; ETA %0.0f s / %s" % (k, fac, 100*k/fac, ettc, eta), end=' ', flush=True)
M = Matrix(symmetrictoeplitz(row))
perm = M.permanent()
if perm > maxperm: maxperm, maxmat = perm, M
if perm < minperm: minperm, minmat = perm, M
outstr = "%d: %d and %d" % (n, minperm, maxperm)
print(('\b'*160) + outstr + (" " * (79-len(outstr))))
"""
n: A351021(n) and A351022(n)
0: 1 and 1
1: 2 and 2
2: 13 and 13
3: 166 and 289
4: 4009 and 13814
5: 169469 and 1795898
6: 10949857 and 265709592
7: 1078348288 and 70163924440
8: 138679521597 and 20610999526800
9: 24402542896843 and 9097511018219760
10: 5348124003487173 and 6845834489829830144
"""