Created
          December 13, 2011 21:38 
        
      - 
      
- 
        Save phill-tornroth/1474006 to your computer and use it in GitHub Desktop. 
    Testing this comment: http://news.ycombinator.com/item?id=3349172
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import sys | |
| valid_words = set([ | |
| 'AA', 'AB', 'AD', 'AE', 'AG', 'AH', 'AI', 'AL', 'AM', 'AN', 'AR', 'AS', 'AT', 'AW', 'AX', 'AY', | |
| 'BA', 'BE', 'BI', 'BO', 'BY', | |
| 'DE', 'DO', | |
| 'ED', 'EF', 'EH', 'EL', 'EM', 'EN', 'ER', 'ES', 'ET', 'EX', | |
| 'FA', 'FE', | |
| 'GO', | |
| 'HA', 'HE', 'HI', 'HM', 'HO', | |
| 'ID', 'IF', 'IN', 'IS', 'IT', | |
| 'JO', | |
| 'KA', 'KI', | |
| 'LA', 'LI', 'LO', | |
| 'MA', 'ME', 'MI', 'MM', 'MO', 'MU', 'MY', | |
| 'NA', 'NE', 'NO', 'NU', | |
| 'OD', 'OE', 'OF', 'OH', 'OI', 'OM', 'ON', 'OP', 'OR', 'OS', 'OW', 'OX', 'OY', | |
| 'PA', 'PE', 'PI', | |
| 'QI', | |
| 'RE', | |
| 'SH', 'SI', 'SO', | |
| 'TA', 'TI', 'TO', | |
| 'UH', 'UM', 'UN', 'UP', 'US', 'UT', | |
| 'WE', 'WO', | |
| 'XI', 'XU', | |
| 'YA', 'YE', 'YO', | |
| 'ZA', | |
| ]) | |
| used_pairs = {} | |
| winners = set() | |
| dict_file = sys.argv[1] | |
| print "Loading %s" % (dict_file,) | |
| dictionary = list() | |
| for word in open(dict_file, mode="r"): | |
| dictionary.append(word.strip().upper()) | |
| print "Loaded %s words" % (len(dictionary),) | |
| for word in dictionary: | |
| word_won = True | |
| i = 0 | |
| while i+1 < len(word) and word_won: | |
| word_part = word[i:i+2] | |
| if word_part in valid_words: | |
| i += 1 | |
| if word_part in used_pairs: | |
| used_pairs[word_part].append(word) | |
| else: | |
| used_pairs[word_part] = [word] | |
| else: | |
| word_won = False | |
| if word_won: | |
| winners.add(word) | |
| print "Qualified words for phrases:" | |
| print " %s" % (winners,) | |
| print "Found scrabble words:" | |
| print " %s" % (used_pairs.keys(),) | |
| print "Never found scrabbled words: " | |
| print " %s" % (valid_words.difference(used_pairs),) | |
| """ | |
| Loading american-words.95 | |
| Loaded 2978 words | |
| Qualified words for phrases: | |
| set(['MELINE', 'ESOP', 'HEMAD', 'SHERE', 'WER', 'UNENAMORED', 'MYOHEMATIN', 'REHONOR', 'HEMATOSIN', 'ANEMATOSIS', 'TORET', 'HEMATID']) | |
| Found scrabble words: | |
| ['BE', 'WE', 'BA', 'WO', 'BO', 'BI', 'JO', 'RE', 'GO', 'ON', 'OM', 'OI', 'OH', 'OF', 'OD', 'OY', 'OX', 'OW', 'OS', 'OR', 'OP', 'HI', 'HO', 'HM', 'HA', 'HE', 'PA', 'PE', 'PI', 'EM', 'EL', 'EN', 'EH', 'ED', 'EF', 'IT', 'EX', 'ET', 'ES', 'ER', 'ME', 'MA', 'MM', 'UT', 'MO', 'MI', 'UP', 'US', 'UM', 'UN', 'MY', 'FA', 'FE', 'NO', 'NA', 'NE', 'NU', 'XI', 'KA', 'KI', 'SI', 'SH', 'SO', 'DO', 'YO', 'YA', 'DE', 'YE', 'MU', 'LA', 'LO', 'LI', 'TO', 'TI', 'TA', 'AB', 'AE', 'AD', 'AG', 'AI', 'AH', 'IS', 'AM', 'AL', 'AN', 'AS', 'AR', 'AT', 'IN', 'AX', 'ID', 'IF'] | |
| Never found scrabbled words: | |
| set(['AA', 'OE', 'ZA', 'QI', 'UH', 'AW', 'AY', 'BY', 'XU']) | |
| """ | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment