﻿def conway(n):
    s = "1"
    i = 0
    while i < n:
        print(s)
        i += 1
        chf = s[0]
        occ = 1
        s2 = ""
        for ind in range(1,len(s)):
            if s[ind] != chf:
                s2 += str(occ) + chf
                chf = s[ind]
                occ = 1
            else:
                occ += 1
        s = s2 + str(occ) + chf

def pascal_add(n):
    l = []
    i = 0
    while(i < n):
        l.append(1)
        for ind in range(len(l)-2,0,-1):
            l[ind] += l[ind-1]
        i += 1
    print(l) # pour respecter l'énoncé
    return l # pour effectivement compléter le code

def pascal_mult(n):
    l = []
    i = 0
    while(i < n):
        l.append(1)
        for ind in range(len(l)-2,0,-1):
            l[ind] = l[ind-1]*i//ind
        i += 1
    print(l)

from time import clock

def temps_calcul_pascal(n,add):
    t = clock()
    if add:
        pascal_add(n)
    else:
        pascal_mult(n)
    print (clock() - t)

import numpy

def pgcd_poly_v1(p1,p2): # ne marche déjà pas pour X²-3X+2 et X²-5X+6, erreur d'approximation
    l1 = list(p1.r)
    l2 = list(p2.r)
    l = []
    for racine in l1:
        if racine in l2:
            l2.remove(racine)
            l.append(racine)
    return numpy.poly1d(l,True)

def pgcd_poly_v2(p1,p2):
    if len(p1) < len(p2): # C'est bien le degré ! Mais sinon p1.order convient
        p1,p2 = p2,p1 # Une étape non nécessaire
    while p2 != numpy.poly1d([0]):
        (_,r) = polydiv(p1,p2)
        p1,p2 = p2,r
    return p1/p1[p1.order] # Quand bien même la liste des coefficients se donne en commençant par le plus haut degré, l'indexation est inversée

