DEV Community

Discussion on: Daily Challenge #282 - Car License Plate Calculator

Collapse
 
vroshupkin profile image
RVados

With the use UTF-8 table

Lowercase alphabet position 97-122
For the 'abz099' Result:

addNum=1000(01+126+25262) addNum = 1000 * (0 * 1 + 1 * 26 + 25 * 26 ^ 2)

And add 99

def find_plate(number_plate):
    byte_array = number_plate.encode(encoding="utf-8")
    add_num = byte_array[0] - 97 + (byte_array[1] - 97) * 26 + (byte_array[2] - 97) * (26 ** 2)
    return 1000 * add_num + int(byte_array[3:6])