Created
August 22, 2021 04:55
-
-
Save goish135/f5f148d5ebce57f79d619b5ced181f65 to your computer and use it in GitHub Desktop.
This file contains 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
'''Ex | |
testStr = "423692" | |
kb = "923857614" | |
''' | |
'''ex1 | |
testStr = "5111" | |
kb = "752961348" | |
''' | |
#'''ex2 | |
testStr = "91566165" | |
kb = "639485712" | |
#''' | |
lookup = {} | |
lookup[1] = [2,4,5] | |
lookup[2] = [1,4,5,6,3] | |
lookup[3] = [2,5,6] | |
lookup[4] = [1,2,5,7,8] | |
lookup[5] = [1,2,3,4,6,7,8,9] | |
lookup[6] = [2,3,5,8,9] | |
lookup[7] = [4,5,8] | |
lookup[8] = [7,4,5,6,9] | |
lookup[9] = [8,5,6] | |
''' | |
print(kb.index(testStr[0])+1) | |
print(kb.index(testStr[1])+1) | |
near = kb.index(testStr[1])+1 | |
print(near in lookup[kb.index(testStr[0])+1]) | |
''' | |
steps = 0 | |
for i in range(len(testStr)-1): | |
#print(i) | |
src = kb.index(testStr[i])+1 | |
dst = kb.index(testStr[i+1])+1 | |
if src==dst: | |
continue | |
elif dst in lookup[src]: | |
steps+=1 | |
else: | |
steps+=2 | |
print(steps) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment