-
Notifications
You must be signed in to change notification settings - Fork 0
/
swapchain.py
57 lines (52 loc) · 1.73 KB
/
swapchain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#From a phonecall with a friend at Google, this is one of their interview questions
#TODO, finish this
#
#1) character count
#
#
#
#2 english strings. Transform 1 word to the other 1 letter at a time.
#
#input: fog, dig
#output: len(fog dog dig)
#
#maintain: levels away from input, which character we are on*****
#
#[fog:(0,true), cog:(1,false), dog:(1,false)]
#
#assume: isEnglishWord(aString)
#
#######
#
#
#
#shorthand
import sys
alphabet = ['a','b','c','d','e','f', 'g', 'h', 'i' , 'j', 'k' ,'l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
def isEnglishWord(someString):
return True
def lengthOfTrain(start, dest):
distance_from_start = 0
train_map = {start:(0,False)}
return evaluateDerivitives(start, dest, train_map, distance_from_start)
def evaluateDerivitives(start, dest, train_map, distance_from_start):
distance_from_start += 1
for word in train_map:
for character_position in range(0,len(word)):
for char in alphabet:
#1
print word, character_position, char
new_word = word.replace(character_position, char, 1)
print "we have a new word: ", new_word
if train_map.get(new_word, False):
if new_word == dest:
return train_map[new_word][1]
if (isEnglishWord(new_word)):
tup = (distance_from_start, False)
train_map[new_word] = tup
evaluateDerivitives(start, dest, train_map, distance_from_start)
train_map[new_word][1] = true
print train_map
print "start train"
lengthOfTrain(sys.argv[1], sys.argv[2])
print "end train"