Normally, we decompose a number into binary digits by assigning it with powers of 2, with a coefficient of `0` or `1` for each term:

`25 = 1*16 + 1*8 + 0*4 + 0*2 + 1*1`

The choice of `0` and `1` is... not very binary. We shall perform the *true* binary expansion by expanding with powers of 2, but with a coefficient of `1` or `-1` instead:

`25 = 1*16 + 1*8 + 1*4 - 1*2 - 1*1`

Now *this* looks binary.

---

Given any positive number `n`, expand it using the true binary expansion, and return the result as an array, from the most significant digit to the least significant digit.

`true_binary(25) == [1,1,1,-1,-1]`

It should be trivial (the proofs are left as an exercise to the reader) to see that:

- Every odd number has infinitely many true binary expansions
- Every even number has no true binary expansions

Hence, `n` will always be an odd number, and you should return the *least* true binary expansion for any `n`.

Also, note that `n` can be very, very large, so your code should be very efficient.

Difficulty: introductory

Starter code:

def true_binary(n):
	

Solutions:
def true_binary(n):
    return [(c == '1') * 2 - 1 for c in '1' + bin(n)[2:-1]]

def true_binary(n):
    return [-1 if x == '0' else 1 for x in bin(n)[1:-1]]

def true_binary(n):
    return [1] + [1 if b=='1' else -1 for b in bin(n)[2:-1]]

def true_binary(n):
    return  [1 if d == "1" else -1 for d in (f"1{n>>1:b}" if n > 1 else "1")]


true_binary=lambda n:[1]+[int(c)*2-1 for c in bin(n)[2:-1]]

import math as m
def true_binary(n):
    c = 1
    c = m.ceil(m.log(n,2))
    if c == 0:
        c = 1
    n = (n+(2**c-1))//2

    return [(char == '1')*2-1 for char in bin(n)[2:]]

def true_binary(n):
    temp=bin(n)[2:]
    return [1 if i=="1" else -1 for i in temp[-1]+temp[:-1]]

def true_binary(n):
    temp=bin(n)[2:]
    res=[]
    for i in temp[-1]+temp[:-1]:
        res.append(1) if i=="1" else res.append(-1)
    return res

def true_binary(n):
    suma = "{:0b}".format(n)
    ans = [int(suma[0])]
    for i in range(1,len(suma)):
        if suma[i-1] == "0": ans.append(-1)
        else: ans.append(1)
    return ans

import re
def true_binary(n):
    s = bin(n)[2:]
    s = re.sub(r'0+1', lambda x: '1' + '0'*(len(x[0])-1), s)
    return [1 if c == '1' else -1 for c in s]