#------------------------TD4------------------------#


#####################[Code 1]##########################

def est_premier(nombre):
    for i in range(2, nombre):
        if nombre % i == 0:
             return False
    return True

for i in range(1, 101):
    print(i, est_premier(i))



#####################[Code 2]##########################

def est_premier(nombre):
    for i in range(2, nombre):
        if nombre % i == 0:
             return False
    return True

def firstnprimes(n):
    i = 0
    nombre = 1
    while i < n:
        if est_premier(nombre) == True:
            print(nombre)
            i = i + 1           
        nombre = nombre + 1

n = int(input("Enter n: "))
firstnprimes(n)



#####################[Code 3]##########################

def Fun1(mylist):
    for i in range(len(mylist)):
        if mylist[i]%2==0:
            mylist[i]/=2
        else:
            mylist[i]*=2

list1 =[21,20,6,7,9,18,100,50,13]
Fun1(list1)
print(list1)



#####################[Code 4]##########################

def f(x):
    return 3*(x**2) - x + 2



#####################[Code 5]##########################

def my_max(x,y):
    if x >= y: 
        return x
    else:
        return y



#####################[Code 6]##########################

def my_max(x,y):
    if x >= y: 
        return x
    return y



#####################[Code 7]##########################

def patternMatching(A,s):
    B = []
    for word in A:
        j = 0
        for i in range(0, len(word)):
            if j < len(s) and word[i] == s[j]:
                j += 1

        if j == len(s):
            B.append(True)
        else: B.append(False)

    return B

A = ["FooBar","FooBarTest","Football","FrameBuffer","ForceLack"]
s = "FB"
print( patternMatching(A, s) )



#####################[Code 8]##########################

def lastStoneWeight(A):
    while len(A) > 1:
        max1, max2 = 0, 1
        if A[max1] < A[max2]:
            max1, max2 = max2, max1

        for i in range(2, len(A)):
            if A[i] > A[max1]:
                max2 = max1
                max1 = i
            elif A[i] > A[max2]:
                max2 = i

        A[max1] -= A[max2]
        A.pop(max2)
        if A[max1] == 0: 
            A.pop(max1)
    return A

A = [2,7,4,1,8,1]
print( lastStoneWeight(A) )



#####################[Code 9]##########################

def lastStoneWeight(A):
    while len(A) > 1:
        max1 = max(A)
        A.remove(max1)

        max2 = max(A)
        A.remove(max2)

        if max1 != max2:
            A.append(max1-max2)
    return A

A = [2,7,4,1,8,1]
print( lastStoneWeight(A) )



#####################[Code 10]##########################

def est_premier(nombre):
    if nombre % 2 == 0 or nombre % 3 == 0:
        return False

    for i in range(1, int(nombre/6.0)):
        if nombre % (6*i-1) == 0 or nombre % (6*i+1) == 0:
             return False
    return True

for i in range(4, 101):
    print(i, est_premier(i))



#####################[Code 11]##########################

def g(s):
    c = 1
    output = ''
    for i in range(0, len(s)):
        if (i == len(s)-1) or s[i] != s[i+1]:
            output += str(c) + s[i]
            c = 1
        else:
            c += 1
    return output

def saySequence(n):
    A = ['1']

    for i in range(0, n-1):
        A.append( g(A[-1]) )
    return A

print( saySequence(16) )



#####################[Code 12]##########################

def saySequence(n):
    A = ['1']

    for i in range(0, n):
        s = A[-1]

        count = 1
        next_s = ''
        for j in range(1, len(s)):
            if s[j] == s[j-1]:
                count += 1
            else:
                next_s = next_s + str(count) + s[j-1]
                count = 1
        next_s = next_s + str(count) + s[-1]
        A.append(next_s)

    return A

print( saySequence(5) )



