Skip to content

Instantly share code, notes, and snippets.

@ideamonk
Created March 2, 2011 13:31
Show Gist options
  • Save ideamonk/850932 to your computer and use it in GitHub Desktop.
Save ideamonk/850932 to your computer and use it in GitHub Desktop.
such a fucked up piece of fuck
def findAllPerm(string):
def findAll(slist):
if len(slist)==1:
return slist
else:
biglist = []
for i in xrange(len(slist)):
temp = [slist[i]]
temp.extend(findAll(slist[:i]+slist[i+1:]))
if len(temp)==2 and type(temp[0])==type(''):
temp = ''.join(temp)
biglist.append(temp)
return biglist
def flattenAndAppend(listy_list, prefix):
if len(listy_list)==3 and type(listy_list[1])==type(''):
junk = [prefix + listy_list[0] + x for x in listy_list[1:]]
for j in junk:
try:
goldRush[j]
except:
goldRush[j]=1
muchBiggerList.append(j)
elif len(listy_list)>3 and type(listy_list[1])==type([]):
prefix += listy_list[0]
for x in listy_list[1:]:
flattenAndAppend(x, prefix)
goldRush = {}
muchBiggerList = []
junky_shit = findAll([x for x in string])
if len(junky_shit)<=2:
return junky_shit
else:
for j in junky_shit:
flattenAndAppend(j,'')
return muchBiggerList
print findAllPerm("aaab")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment