<gh_stars>1-10
import happy

def get_sequence(n, niters=20):
    ''' Get the sequence of numbers generated by applying the happy numbers
    algorithm to n. Terminates in 1 if the number is happy

    n: int; the number in question
    niters: int; optional; maximum number of iterations to attempt

    returns: list of ints; the sequence of numbers generated by applying the
    happy numbers algorithm to n
    '''
    num = n
    iters = 1
    sequence = [num]
    while iters < niters:
        num = sum(happy.squares[digit] for digit in str(num))
        sequence.append(num)
        iters += 1
        if (num == 1):
            break
    return sequence

def main():
    nums = xrange(1, 99+1)
    for n in nums:
        seq = get_sequence(n)

        # check that the sequence terminates or goes into a repeat
        assert((1 in seq) or (4 in seq))
        print seq
        print("\n\n")
    return

if __name__ == '__main__':
    main()
