import math def po2(num):#is a number a power of 2 return num != 0 and ((num & (num - 1)) == 0) #the below section gives the terms of A060802 max_term = [1,2,2,3,3,3,4] for x in range(8,1025): low = 2**(int(math.log(x,2))-2)+2 high = 2**(int(math.log(x,2))-1)+2 start = 2**(int(math.log(x,2))) stop = 2**(int(math.log(x*2,2))) mid = (start + stop)/2+1 if x < mid and x-3 < start:#The triplicates max_term.append(low) elif x < mid and max_term[-1] == max_term[-2]:#increase by one max_term.append(max_term[-1]+1) elif x < mid and max_term[-1] != max_term[-2]:#duplicate the prev. term max_term.append(max_term[-1]) else:#the second half run up to the subsequent power of 2 max_term.append(max_term[-1]+1) f = open("b060802.txt","w") q = 1 for x in max_term: j = str(q)+" " + str(x) f.write(j) f.write('\n') q += 1 f.close() terms = [(1),(1,2),(1,2),(1,2,3),(1,2,3),(1,2,3),(1,2,4)] g = open("Results.txt","w") count = 1 for x in terms: g.write(str(count)) g.write(", ") g.write(str(x)) g.write('\n') count += 1 for n in range(8,1025):#This term generates one possible set of weights #per the proof given by Jon E. Schoenfield term = [1,2] k = int(1+math.floor(math.log(n,2))) if po2(n): term.append(2**(k-3)+2) elif n < (3*2**(k-2)): term.append(n+1-2**(k-1)+int(math.ceil((3*2**(k-2)-n)/2.0))) else: term.append(int(n+1-2**(k-1))) for a in reversed(range(k-3)):#the terms 1 and 2 and the one just appended q = sum(term[2:]) term.append(max_term[n-q-1]) term.sort() j = '(' j += str(n) j += ", (" for x in term: j += str(x) j += ", " j = j[0:-2] j += ')' g.write(j) g.write('\n') g.close()