Skip to content

Instantly share code, notes, and snippets.

@Zenuncl
Created November 11, 2013 05:19
Show Gist options
  • Save Zenuncl/7408297 to your computer and use it in GitHub Desktop.
Save Zenuncl/7408297 to your computer and use it in GitHub Desktop.
import WordLookup
def changeling(initial,goal,steps):
first=initial
last=goal
### The Word Check Function Part ###
if WordLookup.lookup(initial) == False or WordLookup.lookup(goal) == False:
return "Not in the List"
if initial.islower() == False or goal.islower() == False:
return "Not a lower case"
if steps < 0:
return "Steps is invaild!!"
if len(first) != len(last):
return "The Length of initial word and goal word is not same, cannot make any change..!!"
if steps == 0:
if first == last:
return last
else:
return "No Steps"
### The Word Check Function Part END ###
### The changeling Function Start ###
i=1
if WordLookup.lookup(last[0]+first[1:]) and last[0]+first[1:]!=first :
initial=last[0]+first[1:]
while i!=len(first):
if WordLookup.lookup(first[:i-1]+last[i-1]+first[i:]) and first[:i-1]+last[i-1]+first[i:]!=first:
initial=first[:i-1]+last[i-1]+first[i:]
i+=1
if WordLookup.lookup(first[:len(first)-1]+last[len(initial)-1]) and first[:len(first)-1]+last[len(first)-1]!=first :
initial=first[:len(first)-1]+last[len(initial)-1]
new = changeling(initial,goal,steps-1)
if new:
return first +" , "+ changeling(initial,goal,steps-1)
else:
return None
### The changeling Function End ###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment