Skip to content

Instantly share code, notes, and snippets.

@goish135
Created August 22, 2021 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goish135/f5f148d5ebce57f79d619b5ced181f65 to your computer and use it in GitHub Desktop.
Save goish135/f5f148d5ebce57f79d619b5ced181f65 to your computer and use it in GitHub Desktop.
'''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