Lifeintheshortrun.files.wordpress.com



#Takes a number and returns a list of its digitsdef splot(x):lst = []while x >= 10:lst.append(x%10)x = x//10lst.append(x)return lst#Cuts a list into a list of lists of a predetermined lengths (Use factors only)def cutter(lst, breakpt):newlst = []while lst != []:newlst.append(lst[:breakpt])lst = lst[breakpt:]return newlst#Takes a list of lists and converts all integer values into floatsdef floater(lst):newlst = []for i in lst:newerlst =[]for j in i:newerlst.append(j)newlst.append(newerlst)return newlst#Returns the largest number that can be made from a list of digitsdef largest(lst):return sorted(lst, reverse = True)###Functions specific to 6-digit numbers####Returns the first digit minus the last digit of a #number when it's digits are passed in as a listdef af(lst):return lst[0] - lst[5]#2nd digit minus the 5th digitdef be(lst):return lst[1] - lst[4]#3rd digit minus 4th digitdef cd(lst):return lst[2] - lst[3]#The main function/*I got this algorithm from this illuminating paper: returns a 0 or a 1 depending on whther the number converges*/def kap6con(x):x = largest(splot(x))if af(x) in [0, 1,2,3] or be(x) in [1,2,7,9] or cd(x) in [1,8,9]:return 0elif af(x) == 4:if be(x) != 3:return 0if cd(x) not in [2,3]:return 0return 1elif af(x) == 5:if be(x) != 5:return 0if cd(x) != 0:return 0return 1elif af(x) == 6:if be(x) not in [3,6]:return 0if cd(x) not in [2,3]:return 0return 1elif af(x) == 7:if be(x) == 6:if cd(x) not in [0,4,6]:return 0else:return 1elif be(x) == 4:if cd(x) != 0:return 0else:return 1else:return 0elif af(x) == 8:if be(x) == 8:if cd(x) not in [3,5,7]:return 0else:return 1elif be(x) == 6:if cd(x) not in [4,6]:return 0else:return 1else:return 0elif af(x) == 9:if cd(x) != 0:return 0if be(x) not in [4, 6]:return 0else:return 1#Returns a list of 1s and 0s of the first 'limit' 6-digit numbersdef kap6(limit):lst = []for i in range(10**5, 10**5 + limit):lst.append(kap6con(i))return lst###Generating the plot####Taken from stackexchangeimport numpyimport matplotlib.pylab as pltm = floater(cutter(kap6(900000), 1000)) #Generates the rows of the plotmatrix = numpy.matrix(m)fig = plt.figure()ax = fig.add_subplot(1,1,1)ax.set_aspect('equal')plt.imshow(matrix, interpolation="nearest", cmap=plt.cm.gray)plt.colorbar()plt.show() ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download