## Preface

A collatz sequence, starting with a positive integern, is found by repeatedly applying the following function to n until n == 1 :

`$f(n) =
\begin{cases}
n/2,   \text{  if $n$ is even} \\
3n+1,  \text{  if $n$ is odd}
\end{cases}$`
----

A more detailed description of the collatz conjecture may be found [on Wikipedia](http://en.wikipedia.org/wiki/Collatz_conjecture).

## The Problem

Create a function `collatz` that returns a collatz sequence string starting with the positive integer argument passed into the function, in the following form:

"X0->X1->...->XN"

Where Xi is each iteration of the sequence and N is the length of the sequence.

## Sample Input

```python
collatz(4) # should return "4->2->1"
collatz(3) # should return "3->10->5->16->8->4->2->1"
```

Don't worry about invalid input. Arguments passed into the function are guaranteed to be valid integers >= 1.

Difficulty: introductory

Starter code:

def collatz(n):
	

Solutions:
def collatz(n):
    l = [str(n)]
    while n > 1:
        n = 3 * n + 1 if n % 2 else n / 2
        l.append(str(n))
    return '->'.join(l)

def collatz_step(n):
    if n % 2 == 0:
        return n//2
    else:
        return n*3 + 1

def collatz_seq(n):
    while n != 1:
        yield n
        n = collatz_step(n)
    yield 1

def collatz(n):
    return '->'.join(str(x) for x in collatz_seq(n))


def collatz(n):
  return str(n) + '->' + collatz(3*n+1 if n%2 else n/2) if n != 1 else '1'

def _collatz(n):
    yield n
    while n != 1:
        n = (n // 2, 3 * n + 1)[n % 2]
        yield n

def collatz(n):
    return '->'.join(map(str, _collatz(n)))

def collatz(n):
    ret = []
    while n!= 1:
        ret.append(n)
        n = [n//2, (n*3)+1][n%2]    
    return '->'.join( map( str, ret+[1] ) )

def collatz(n):
    l = [str(n)]
    while n != 1:
        if n%2:
            n = 3*n+1
        else:
            n = n//2
        l.append(str(n))
    return '->'.join(l)

def collatz(n):
    numbers = sequence(n)
    result = '->'.join(map(str, numbers))
    return result


def sequence(n):
    if n == 1:
        return [1]
    elif n % 2 == 0:
        return [n] + sequence(n // 2)
    else:
        return [n] + sequence(3 * n + 1)

def collatz(n):
    def f(n):
        while True:
            yield str(n)
            if n == 1:
                break
            elif n % 2:
                n = 3*n + 1
            else:
                n //= 2
    return '->'.join(f(n))

def collatz(n):
    collatz = str(n) + '->'
    while n != 1:
        n = n / 2 if n % 2 == 0 else n * 3 + 1
        collatz += str(n) + '->'
    return collatz.rstrip('->')

def collatz(n):
    seq = [str(n)]
    while n > 1:
        n = (3 * n + 1) if (n % 2) else (n // 2)
        seq.append(str(n))
    return "->".join(seq)