def sift3_distance(s_1, s_2, max_offset=5):
    """Calculate string distance

    See http://siderite.blogspot.com/2007/04/super-fast-and-accurate-string-\
distance.html for background. This is a port of sift3Distance from mailcheck.js
    rather than the Python code from https://gist.github.com/fjorgemota/3067867
    because the latter produces different results.

    :param s_1: first string
    :param s_2: second string
    :param max_offset: maximum offset, default: 5
    :type s_1: str
    :type s_2: str
    :type max_offset: int
    :returns: string distance
    :rtype: int
    """
    len_s_1 = len(s_1)
    len_s_2 = len(s_2)

    if len_s_1 == 0:
        if len_s_2 == 0:
            return 0
        else:
            return len_s_2

    if len_s_2 == 0:
        return len_s_1

    c = 0
    offset_1 = 0
    offset_2 = 0
    lcs = 0

    while (c + offset_1 < len_s_1) and (c + offset_2 < len_s_2):
        if s_1[c + offset_1] == s_2[c + offset_2]:
            lcs += 1
        else:
            offset_1 = 0
            offset_2 = 0
            for i in range(0, max_offset):
                if (c + i < len_s_1) and (s_1[c + i] == s_2[c]):
                    offset_1 = i
                    break
                if (c + i < len_s_2) and (s_1[c] == s_2[c + i]):
                    offset_2 = i
                    break
        c += 1
    return (len_s_1 + len_s_2) / 2.0 - lcs