Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def absoluteValue ( x ):
- if ( x >= 0 ):
- return x
- else:
- return -x
- def findCoordinates ( num ):
- if ( num == 1 ):
- return [ 0, 0 ]
- if ( num == 2 ):
- return [ 0, 1 ]
- if ( num == 3 ):
- return [ 0, 2 ]
- if ( num == 4 ):
- return [ 1, 0 ]
- if ( num == 5 ):
- return [ 1, 1 ]
- if ( num == 6 ):
- return [ 1, 2 ]
- if ( num == 7 ):
- return [ 2, 0 ]
- if ( num == 8 ):
- return [ 2, 1 ]
- if ( num == 9 ):
- return [ 2, 2 ]
- if ( num == 0 ):
- return [ 3, 1 ]
- return [ -1, -1 ]
- def distance ( first, second ):
- positionFirst = findCoordinates ( first )
- positionSecond = findCoordinates ( second )
- xDifference = absoluteValue ( positionFirst [ 0 ] - positionSecond [ 0 ] )
- yDifference = absoluteValue ( positionFirst [ 1 ] - positionSecond [ 1 ] )
- return xDifference + yDifference
- phoneNumber = input ( "> Insert phone number: " )
- phoneNumberList = []
- for x in range ( 0, len ( phoneNumber ) ):
- phoneNumberList.append( int ( phoneNumber [ x ] ) )
- print ( phoneNumberList )
- totalDistance = distance ( 0, phoneNumberList [ 0 ] )
- for x in range ( 0, len ( phoneNumber ) - 1 ):
- totalDistance = totalDistance + distance ( phoneNumberList [ x ], phoneNumberList [ x + 1 ] )
- print ( totalDistance + len ( phoneNumber ) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement