#!/usr/bin/python # version one # get the base-36 digit that the base-36 digits in each words add up to, then that those digits add up to, then that those digits add up to, ahh, # until we get a single digit between 0 and z for each word. Then we play all the words that came to 0 (if any) in the order they appeared, then # the ones that added up 1 in order, then 2, then 3, to z. FUN # I'll make a bunch of other ones that do other things method = 1 # methods> # 1 >>>>>> play all the words of order 0, then order 1, then order 2, up to z, in the order they appeared # 2 >>>>>> play the first word of order 0, then the first word of order 1, then 2,up to z, then the next word of order 0, til no words # remain for any order # 3 >>>>>> fibonacci value chaining, modulo the base, with chronology # unless -scramble is on, then no chrono. turn off verbose # to get rid of deflation notices and pops. # 4 >>>>>> same as 3 but values are multiplied not summed. like in # mult mode of series.py, zeroes are treated as ones. # actually go on and use this one with -mult. you get # next distributions. this might get stuck on one tier # if two words with the same value multiply to that # value. then you won't get any other tiers' words til # that one pops. i think that's less likely to happen # with 3 than 4. 4 is really fun but I am gonna do a # novel in this right now and I'll use 3 to avoid # getting stuck on a track. savvy # just say "-method n" on the commandline # flamoot, add a method where one word's value is used as an index # or offset into the tier the other word's value specifies, instead # of using chronology/position. method 5 # figure out if methods 3 and 4 bog down on a tier. 3 might do it # on 0 but i can't quite figure out how. 4 could do it if it gets # two values worth one or two that multiply modulo the base to # themselves, if there are any such values. i could put in some # kind of halting check and skip it out of a track it spends too # long in. it didn't occur to me it's not gonna pull words off # each tier with a different value than the previous one. each # tier's words all have the same value, the tier's. sheesh base = 36 # 10 or 36 or whatever you want. digits are always read in in base # 36 (that's how we use text). say "-base n" on the commandline to # set this to n dynamically. mult = 0 # << if you want to do products instead of sums, set this to 1 # or say -mult on the commandline scramble = 0 # shuffle up resulting blocks of text, depending on method, and if the method supports it # Can either set this to 1 or say -scramble on the commandline # Works in methods: 1, 2, 3, 4 verbose = 1 # more output import random, sys, os l = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] num_rep={'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9, 'a':10, 'b':11, 'c':12, 'd':13, 'e':14, 'f':15, 'g':16, 'h':17, 'i':18, 'j':19, 'k':20, 'l':21, 'm':22, 'n':23, 'o':24, 'p':25, 'q':26, 'r':27, 's':28, 't':29, 'u':30, 'v':31, 'w':32, 'x':33, 'y':34, 'z':35} if sys.argv.__contains__("-h") or sys.argv.__contains__("-help") \ or sys.argv.__contains__("--help"): print "numerolit.py usage\n" print "cat some.txt | ./numerolit.py [-mult] [-scramble] [-base n] [-method n] > outputfile" print "\nValid methods are 1 to 3. See the script's comments for advice" sys.exit() newbase = 0 try: newbase = int(sys.argv[sys.argv.index("-base")+1]) except: pass if newbase != 0: if newbase > 1 and newbase < 37: base = newbase else: print "Err: argument to -base must be 2 to 36" sys.exit() newmethod = 0 try: newmethod = int(sys.argv[sys.argv.index("-method")+1]) except: pass if newmethod != 0: if newmethod > 0 and newmethod < 5: method = newmethod else: print "Err: argument to -method must be 1 to 4" sys.exit() if sys.argv.__contains__("-mult"): mult = 1 if sys.argv.__contains__("-scramble"): scramble = 1 lines = sys.stdin.readlines() lines = " ".join(lines).replace("\n", " ") while lines.replace(" ", " ") != lines: lines = lines.replace(" ", " ") (w,r) = os.popen2("perl -ne '$_ = lc $_;s/\\t/ /g;s/[^a-z0-9 ]//g; print'") w.write(lines) w.close() lines = " ".join(r.readlines()).replace("\n"," ") r.close() while lines.replace(" ", " ") != lines: lines = lines.replace(" ", " ") aaa = "" if mult == 1: aaa += " -mult" (w,r) = os.popen2("./series.py -high "+aaa) w.write("base "+str(base)+"\nfrombase36\n"+lines+"\nfrombase "+str(base)+"\nreiterhi\nquit\n") w.close() series = "" inlines = r.readlines() #print "".join(inlines) #sys.exit() freqs = "" freq = 0 for n in xrange(1, len(inlines)): if inlines[0-n].strip().endswith(">"): freq = 1 continue if freq == 1: freqs = inlines[0-n] + freqs if inlines[0-n].startswith("Series is "): series = inlines[0-(n+1)] break if series == "": print "No series retrieved, something bork-ed" sys.exit() if verbose == 1: print freqs #print series a = [] b = [] for word in lines.split(" "): word = word.strip() if word != "": a.append(word.replace("\n","")) for word in series.split(" "): word = word.strip() if word != "": b.append(word) if verbose == 1: print "Number of words counted: "+str(len(a)) if verbose == 1: print "Number of digits counted: "+str(len(b)) if len(a) != len(b): if verbose == 0: print "Number of words counted: "+str(len(a)) print "Number of digits counted: "+str(len(b)) print "Mismatch! Failure! Bailing!" sys.exit() else: if verbose == 1: print "A perfect match! Ready to numerol-it" wordsout = 0 if method == 1: ################### # METHOD ONE STARTS ################### if verbose == 1: print "\nUsing method 1: individual pools of like-ranking words\n" hash = {} position = {} basecheck = 0 for t in l: position.update({t:0}) #print position c = 0 for word in a: num = b[c] hash.update({str(num)+"-"+str(position[num]):word}) position[num] += 1 c += 1 for n in l: strr = "" if verbose == 1: print "\nWords", if mult == 0: print "summing", elif mult == 1: print "multiplying", print "in base-"+str(base)+" to \""+n+"\"", tabctr = 0 owo = wordsout for c in xrange(len(a)): if hash.has_key(str(n)+"-"+str(c)): strr += hash[str(n)+"-"+str(c)]+" " wordsout += 1 tabctr += 1 if tabctr == 100: strr = strr.strip()+"\n" tabctr = 0 if scramble == 1: t = strr.split(" ") random.shuffle(t) strr = " ".join(t) if verbose == 1: print "(there are "+str(wordsout-owo)+" of them.)" print strr.strip()+"." basecheck += 1 if basecheck >= base: break elif method == 2: ################### # METHOD TWO STARTS ################### if verbose == 1: print "\nUsing method 2: incremental rotating selection from each word rank\n" hash = {} position = {} for t in l: position.update({t:0}) #print position c = 0 for word in a: num = b[c] hash.update({str(num)+"-"+str(position[num]):word}) position[num] += 1 c += 1 tabctr = 0 for c in xrange(len(a)): # if verbose == 1: print "\nWord #"+str(c)+" from base-36 orders 0 to z" owo = wordsout tabctr += 1 basecheck = 0 strr = "" for n in l: if hash.has_key(str(n)+"-"+str(c)): strr += hash[str(n)+"-"+str(c)]+" " wordsout += 1 tabctr += 1 if tabctr == 100: tabctr = 0 strr = strr.strip()+"\n" if scramble == 1: t = strr.split(" ") random.shuffle(t) strr = " ".join(t) strr = strr.replace(" ", " ") # if len(strr.split(" ")) > 10: # print strr.strip()+"." if len(strr.strip()) < 40: print strr.strip(), # no periods in method 2. they're too arbitrary. i decided else: print strr.strip() tabctr = 0 if owo == wordsout: # we can't find any more words break basecheck += 1 if basecheck >= base: break strr = strr.replace(" ", " ") # grr if len(strr.split(" ")) <= 5 and strr.strip() != "": print strr+"." # makin sure elif method == 3 or method == 4: ########################### # METHODS THREE/FOUR STARTS ########################### if method == 4: stache = " (multiplying)" else: stache = "" if verbose == 1: print "\nUsing method "+str(method)+": positional-fibonacci word value chaining"+stache+"\n" hash = {} position = {} deflated = {} deflations = "" basecheck = 0 for t in l: position.update({t:0}) deflated.update({t:0}) #print position c = 0 word1 = "" word2 = "" for word in a: num = b[c] # if word1 == "": # word1 = word # elif word1 != "" and word2 == "": # word2 = word hash.update({str(num)+"-"+str(position[num]):word}) position[num] += 1 c += 1 for t in l: position.update({t:0}) keepItUp = 1 c = 0 word1 = "" word2 = a[1] num1 = "" num2 = b[1] tabctr = 0 strr = "" nextword = "" nextnum = 0 oldnext = 0 while keepItUp == 1: word1 = word2 word2 = nextword strr += word2+" " num1 = num2 num2 = nextnum if tabctr == 100: tabctr = 0 strr = (strr.strip()+"\n").replace("..",".") tabctr += 1 # methods 3 and 4 place their own newlines, these are dumb then if method == 3: next = (int(num_rep[str(num1)]) + int(num_rep[str(num2)])) % base elif method == 4: k = int(num_rep[str(num1)]) p = int(num_rep[str(num2)]) if k == 0: k = 1 if p == 0: p = 1 next = (k * p) % base nextword = "" tries = 0 while tries < base*2 and nextword == "": if hash.has_key(str(l[next])+"-"+str(position[l[next]])): nextword = hash[str(l[next])+"-"+str(position[l[next]])] nextnum = l[next] position[l[next]] += 1 wordsout += 1 #print "next: "+str(next) #print "l[next]: "+str(l[next]) #print "position[l[next]]: "+str(position[l[next]]) #print repr(hash)[:78] #print str(l[next])+"-"+str(position[l[next]]) #print "nextword: "+nextword #print "nextnum: "+str(l[next]) #print "oldnext: "+str(l[oldnext]) break else: if deflated[l[next]] == 0 and position[l[next]] > 0: if verbose == 1: strr += "(pop \""+l[next]+"\") " deflations += "\ndeflated word pool number \""+l[next]+"\" " deflated[l[next]] = 1 mystr = [] idx = 0 while 1: # hmm if hash.has_key(str(l[next])+"-"+str(idx)): mystr.append(hash[str(l[next])+"-"+str(idx)]) idx += 1 else: break mystr = list(set(mystr)) mystr.sort() only = "" if len(mystr) < 51: only = "only " deflations += "(which held "+str(idx)+" total words, "+only+str(len(mystr))+" unique, "+str(deflated.values().count(0))+" pools remain, of "+str(len(deflated.values()))+"):" if len(mystr) < 51: deflations += "\n"+" ".join(mystr)+".\n" else: deflations += "\n"+" ".join(mystr[0:50])+".\n" #print "next: "+str(next) #print "l[next]: "+str(l[next]) #print "position[l[next]]: "+str(position[l[next]]) #print repr(hash)[:78] #print str(l[next])+"-"+str(position[l[next]]) if not strr.strip().endswith("."): if len(strr.split(" ")) > 50: #print strr.split(" ") if scramble == 1: t = strr.strip().split(" ") random.shuffle(t) strr = " ".join(t)+" " strr = strr.strip() # + ". " if strr.strip().replace(".","") != "": print strr tabctr = 0 if verbose == 1 and deflations != "": print "\n"+deflations+"\n" deflations = "" strr = "" sys.stdout.flush() next = (next + 1) % base tries += 1 if nextword == "": keepItUp = 0 print (strr.strip()+".").replace("..",".").replace(". .",".") # god if verbose == 1: print "No more words. Fibonacci value chaining all done. Good!" else: oldnext = next if verbose == 1: print "\nWords out: "+str(wordsout)+" out of "+str(len(a)) if wordsout != len(b): if verbose == 0: print "\nWords out: "+str(wordsout)+" out of "+str(len(a)) print "Mismatch! Failure! But now it's too late to care!" sys.exit() else: if verbose == 1: print "A perfect match! We've done a great job as always" if verbose == 1: print "Bye bye, flamoot"