Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Simple Particle Engine for a shooter game
Snake / Nibbles clone in C and Ncurses
Please improve
Parsing of XML data has high CPU usage
Convert simple Javascript to jQuery plugin
Active Record getting unique records
List the files in a directory without the directory name or the extension
clean the code
ohs system, recruitment software, hr software, oh&s software, human resources software, ohs software
Array parsing in a block
Popular
Parsing of XML data has high CPU usage
Please improve
Snake / Nibbles clone in C and Ncurses
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Simple Particle Engine for a shooter game
Active Record getting unique records
Breadth first cartesian product iterator
php refactoring
first BST
Pastable version of
Williams Words
<pre class='prettyprint' language='python'>import sys #input into this structure words = {} #strings generated go here gen = [] #input word word = "" #final output final = [] #first arg = word to parse, second arg = wordlist name, optional, third arg = (generated word) minimum length, optional arglength = len(sys.argv) if arglength > 1: word = sys.argv[1] else: print "Please specify an input file" quit() if arglength > 2: list = sys.argv[2] else: print "Using default wordlist.txt" list = "wordlist.txt" if arglength > 3: cutoff = int(sys.argv[3]) else: print "Using default cutoff of 1 letter" cutoff = 1 #create output file based on the word we're generating outFile = "output-" + word + ".txt" out = open(outFile, 'w') #create input file f = open(list,'r') #file is one word per line, strip out the endline character, and throw in a dictionary for line in f: line = line.strip() if len(line) > cutoff: words[line] = 1 #recurse calculates all the substrings forward, is exponential #input: current string, base string #example: spray => recurse("s","pray"), recurse("","pray") def recurse(current, string): if string == "": return gen.append(current) gen.append(str(current + string[:1])) recurse(current, string[1:]) recurse(str(current + string[:1]), string[1:]) #check the generated strings for words #input: string list, word list def checkOverlap(gen, words): for item in gen: #these are just strings, so lets check if they're words if item in words: #ignoring duplicates as we go if item not in final: final.append(item) #start recursion on the input word recurse("", word) #given the generated strings, find the words checkOverlap(gen, words) #sort the output final.sort() #write the output for item in final: out.write(item) out.write('\n') print "Output written to " + outFile</pre> <a href="http://www.refactormycode.com/codes/627-williams-words" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>