def collatz_sequence(n):
    """
    The Collatz sequence for n is a generated by iterating:

    a_n = (1/2) * a_n-1    if a_n-1 is even
    a_n = 3*a_n-1 + 1      if a_n-1 is odd

    ...a sequence which is conjectured to always wind up at 1.
    """
    s = []
    x = n
    while x>1:
        s.append(x)
        if x % 2 == 0:
            x = x//2
        else:
            x = 3*x + 1
    return s