def count_stars(chars):
    """
    Count the number of trailing '#' (~== '#+$')

    >>> count_stars("http://example.org/p?q#fragment####")
    <<< 4
    """
    count = 0
    for c in chars[::-1]:
        if c != '#':
            break
        count += 1
    return count