Shared2018-10-10-212036.sagewsOpen in CoCalc
Scratch work on decompositions
list = [1,2,3,4]
list
[1, 2, 3, 4]
list2 = [x^2 for x in [1,2,..,10]]
list2
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
def decomp(n,k):
if (k-1)/2 < n/k:
return [n/k - (k-1)/2 + i for i in [0, 1, .. , k-1]]
else:
return [(k-1)/2 - n/k + i for i in [1,2, .. , 2*n/k]]
decomp(45,9)
[1, 2, 3, 4, 5, 6, 7, 8, 9]

decomp(180,9)
[16, 17, 18, 19, 20, 21, 22, 23, 24]
decomp(45,4)
[39/4, 43/4, 47/4, 51/4]
list[0]
1
def name_decomp(n):
if n % 2 == 0:
for k in [1,3,..,n-1]:
if decomp(n,k)[0].is_integer() and decomp(n,k)[0]>0 :
print decomp(n,k), k
if n % 2 == 1:
for k in [1,3,..,n]:
if decomp(n,k)[0].is_integer() and decomp(n,k)[0]>0 :
print decomp(n,k), k

name_decomp(45)
[45] 1 [14, 15, 16] 3 [7, 8, 9, 10, 11] 5 [1, 2, 3, 4, 5, 6, 7, 8, 9] 9 [5, 6, 7, 8, 9, 10] 15 [22, 23] 45
name_decomp(90)
[90] 1 [29, 30, 31] 3 [16, 17, 18, 19, 20] 5 [6, 7, 8, 9, 10, 11, 12, 13, 14] 9 [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] 15 [21, 22, 23, 24] 45