import time import os for i in range(10): infilename = 'data/pi100m.dectxt.00' + str(i) outfilename = 'data/tau100m.dectxt.00' + str(i) if not os.path.isfile(outfilename): start=time.time() with open(infilename, 'r') as fin: pi = fin.read() overallcount = 100000000 for subset in range(9): pisub = pi[subset*10000000:(subset+1)*10000000] pos = 0 tau = '' pisect='' counter = 0 print "Processing " + infilename + ", remaining (million): ", while pos < len(pisub): if overallcount % 1000000 == 0: print (overallcount / 1000000), overallcount -= 1 if pisub[pos] == '4': counter += 1 # I put in this counter to work on larger chunks, but I'm not convinced it makes a difference if counter % 5 == 0: numsect=int(pisect) pisect='4' numsect *= 2 tau+=str(numsect) else: pisect+=pisub[pos] else: pisect+=pisub[pos] pos += 1 #for the remainder numsect = int(pisect) numsect *= 2 tau+=str(numsect) with open(outfilename, 'a+') as fout: fout.write(tau) print 'Finished, %0.1f minutes elapsed' % ((time.time() - start)/60) else: print outfilename + 'already exists.' print '\nScript finished.' tauday_file = open('data/tau100K-tauday.com.txt', 'r') tauday_string = tauday_file.read() tauday_file.close() this_file = open('data/tau100m.dectxt.000', 'r') this_string = this_file.read() this_file.close() print len(tauday_string) print tauday_string[:10] print this_string[:10] if tauday_string[:99999] == this_string[:99999]: print "Verification successful. Yay." filelist = ['data/tau100m.dectxt.001', 'data/tau100m.dectxt.002', 'data/tau100m.dectxt.003', 'data/tau100m.dectxt.004', 'data/tau100m.dectxt.005', 'data/tau100m.dectxt.006', 'data/tau100m.dectxt.007', 'data/tau100m.dectxt.008', 'data/tau100m.dectxt.009'] for filename in filelist: current = open(filename, 'r') string1K = current.read()[:1000] current.close() newfile = open(filename+'.1K', 'w+') newfile.write(string1K) newfile.close() # verify that pi has a fibonacci sequence of 11235813 at position 48300973 this_file = open('data/pi100m.dectxt.000', 'r') this_string = this_file.read() this_file.close() print this_string[48300973:48300993] # verify that tau has a fibonacci sequence of 1123581321 at position 809073288 this_file = open('data/tau100m.dectxt.008', 'r') this_string = this_file.read() this_file.close() print this_string[9073288:9073300] # verify that tau recapitulates pi at position 52,567,169 this_file = open('data/tau100m.dectxt.000', 'r') this_string = this_file.read() this_file.close() print this_string[52567169:52567189] # verify that tau recapitulates tau at position 405747241 this_file = open('data/tau100m.dectxt.004', 'r') this_string = this_file.read() this_file.close() print this_string[5747241:5747261]