Skip to content

Instantly share code, notes, and snippets.

@tomasn4a
Created March 31, 2016 23:06
Show Gist options
  • Save tomasn4a/a875858ff6ef30acaf08ed75dd1489a1 to your computer and use it in GitHub Desktop.
Save tomasn4a/a875858ff6ef30acaf08ed75dd1489a1 to your computer and use it in GitHub Desktop.
import math
def distance(str):
li_str = list(str)
result = 0
for i in range(1,len(li_str)):
row_prev = get_row(li_str[i-1])
col_prev = get_col(li_str[i-1])
row = get_row(li_str[i])
col = get_col(li_str[i])
result += math.sqrt((row_prev-row)**2 + (col_prev-col)**2)
print("%.2fcm" % result)
def get_row(a):
pad = ("1","2","3","4","5","6","7","8","9",".","0")
return pad.index(a)//3
def get_col(a):
pad = ("1","2","3","4","5","6","7","8","9",".","0")
return pad.index(a)%3
distance("219.45.143.143")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment