2009 108

From XPUB & Lens-Based wiki
Revision as of 12:19, 2 December 2008 by Michael Murtaugh (talk | contribs) (New page: <code lang="python"> def makewordlist (): ret = [] for line in open("words.txt"): word = line.strip() ret.append(word) return ret allwords = makewordlist() # find word pairs # FOR...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

def makewordlist (): ret = [] for line in open("words.txt"): word = line.strip() ret.append(word) return ret

allwords = makewordlist()

  1. find word pairs
  2. FOR EVERY WORD
  3. FLIP THE WORD
  4. CHECK IF FLIPPED WORD IS IN WORDLIST

def find_bisect (wordlist, seekword): bot = 0 top = len(wordlist) count = 0 lastword = None while True: count += 1 mid = bot + ((top - bot) / 2) curword = wordlist[mid] #print "checking item[", mid, "] = ", curword if (curword == seekword): #print "found in", count, "iterations" return True elif (curword < seekword): bot = mid else: top = mid

if curword == lastword: return False lastword = wordlist[mid]

# if you're checking what you just checked, # time to stop

# if it takes more than 18 times stop


  1. word = "geeblosx"
  2. print word, find_bisect(allwords, word)
  3. word = "tomato"
  4. print word, find_bisect(allwords, word)


  1. import sys
  2. sys.exit()

for word in allwords: # flip the word

  1. print "checking", word

flip = word[::-1] # is flip a word # if flip in allwords: if find_bisect(allwords, flip): print "found a word pair", word, flip

#for w in allwords:

    1. print " checking", w

#if w == flip: #print "found a word pair", word, flip #break