## Questions 1
def occur(L,k):
    oc = 0
    for el in L[k:]:
        if el == L[k]:
            oc += 1
        else:
            break
    return oc

L=[1,2,1,1,1,2]
print(occur(L,0), occur(L,2),occur(L,-1))

## Question 2
def atomisation(chaine):
    return [ int(car) for car in chaine]

print(atomisation("1213"))

## Question 3

def decodage(L):
    L_indices = [0]
    N = len(L[1:])
    for k in range(1,N+1):
        if L[k] != L[k-1]:
            L_indices.append(k)
    V = [L[k] for k in L_indices]
    M =[occur(L,k) for k in L_indices]
    return V,M

def bigbang(N):
    u = "1"
    print(u)
    for k in range(N-1):
        L = atomisation(u)
        V,M = decodage(L)
        u=""
        n = len(V)
        for j in range(n):
            u += str(M[j])+str(V[j])
        print(u)

N = 10
bigbang(10)

## Question 4
import matplotlib.pyplot as plt

def bigbang2(N):
    u="1"
    longueurs=[1]
    for k in range(N-1):
        L = atomisation(u)
        V,M = decodage(L)
        u = ""
        n = len(V)
        for j in range(n):
            u += str(M[j])+str(V[j])
        longueurs.append(len(u))
    return longueurs

N = 30
L = bigbang2(N)
plt.title("Longueur des termes de la suite audioactive")
plt.plot(range(N),L,marker='.');
plt.show()