def id_number_checksum(gd):
    """
    Calculates a Swedish ID number checksum, using the Luhn algorithm
    """
    n = s = 0
    for c in (gd['year'] + gd['month'] + gd['day'] + gd['serial']):
        # Letter? It's an interimspersonnummer and we substitute the letter
        # with 1.
        if c.isalpha():
            c = 1

        tmp = ((n % 2) and 1 or 2) * int(c)

        if tmp > 9:
            tmp = sum([int(i) for i in str(tmp)])

        s += tmp
        n += 1

    if (s % 10) == 0:
        return 0

    return (((s // 10) + 1) * 10) - s