Mathématiques en BCPST2

.

Python en BCPST2

TB Informatique 2023

Sujet TB 2023

from random import *

##1

def ber(p):
    if random() < p:
        return 1
    else:
        return 0

##2
T = [0, 1, 1, 0, 1, 0, 1, 1]

print(len(T))

##3

print(T[1])

##4

print([0,0,1,0,1,1,0,1])

##5

def tunnel(T):
    L=len(T)*[0]
    for i in range(0,len(T)-1):
        if T[i] == 1 and T[i+1]==0:
            L[i+1]=1
        if T[i] == 1 and T[i+1]==1:
            L[i]=1
    return L

print(tunnel(T))

##6
def tunnel2 (T,p):
    L=len(T)*[0]
    for i in range (0,len(T) -1):
        if T[i]==1 and T[i +1]==0:
            L[i+1]=1
        if T[i]==1 and T[i +1]==1:
            L[i]=1
    if T [0]==0:
        L[0]=ber(p)
    return (L)

##7
def evol2(T,n,p):
    L=T
    print(L)
    for i in range(n):
        L= tunnel2(L,p)
        print(L)

##8
T=[[0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0],
[0, 0, 1, 0, 1, 0, 1, 0, 0],
[0, 1, 1, 0, 1, 0, 1, 1, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0],
[0, 0, 1, 0, 1, 0, 1, 0, 0],
[0, 1, 1, 0, 1, 0, 1, 1, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0]]

##9
def coq(T):
    L=len(T)*[0]
    for i in range(1,len(T)-1):
        s = T[i-1:i+2]
        if sum(s)%2==1:
            L[i]=1
    return(L)

##10
def evol4(T,n):
    A=[T]
    L=T
    for i in range(n):
        L= coq(L)
        A.append(L)
    return (A)

T = [0]*200+[1]+[0]*200
import matplotlib.pyplot as plt

plt.imshow(evol4(T,400))
plt.show()
##11
# prop3

##12

def voisins(M,i,j):
    V = []
    n=len(M)
    for u in range(max(0,i-1),min(n,i+2)):
        for v in range(max(0,j-1),min(n,j+2)):
            if u!=i and v!=j:
                V.append(M[u][v])
    return V

def epi(T,v):
    n = len(T)
    M = [[0 for _ in range(n)]for _ in range (n)]
    for i in range(n):
        for j in range(n):
            if T[i][j] == 0:
                k = sum(voisins(M,i,j))
                M[i][j]=ber(k*p)
            if T[i][j] == 1:
                M[i][j] = 1
    return M
TB Informatique 2024

Sujet TB 2024

    V##1,2,3,4
    L = [[200, 100, 155], [0, 254, 255]]

    print(L[1],L[1][1],len(L),len(L[1]))
    ##5
    def mz(n,m):
        return [m * [0] for k in range (n)]

    print(mz(2,3))

    ##6

    def taille(L):
        return len(L)*len(L[1])

    ##7

    def negatif(L):
        N = mz(len(L),len(L[0]))
        n = len(L)
        m = len(L[0])
        for i in range(n):
            for j in range(m):
                N[i][j] = 255 - L[i][j]
        return N

    ##8

    def monochrome(L,s):
        M=mz(len(L),len(L[0]))
        n = len(L)
        m = len(L[0])
        for i in range(n):
            for j in range(m):
                if L[i][j]  >= s:
                    M[i][j] = 255
        return M

    ##9

    def reflexion(L):
        R = mz(len(L),len(L[0]))
        n = len(L)
        m = len(L[0])
        for i in range(n):
            for j in range(m):
                R[i][j] = L[i][m - j-1]
        return R

    ##10

    def transpose(L):
        T=mz(len(L[0]),len(L))
        R = mz(len(L),len(L[0]))
        n = len(L)
        m = len(L[0])
        for i in range(n):
            for j in range(m):
                T[i][j] = L[j][i]
        return T

    ##11
    def indmin(L):
        k = 0
        n=len(L)
        for i in range(n):
            if L[i]<L[k]:
                k = i
        return k

    def selection(L):
        n= len(L)
        for i in range(n):
            k = i+indmin(L[i:])
            L[i],L[k] = L[k],L[i]
        return L

    ##12

    def indminPhoto(L):
        k = 0
        n=len(L)
        for i in range(n):
            if L[i][1]<L[k][1]:
                k = i
        return k

    def selectionPhoto(L):
        n= len(L)
        for i in range(n):
            k = i+indminPhoto(L[i:])
            L[i],L[k] = L[k],L[i]
        return L

    ##13
    def dicho(x,T):
        a=0
        b=len(T)-1
        while a < b:
            m=(a+b)//2
            if x==T[m]:
                return True
            elif x<T[m]:
                b=m
            else:
                a=m
        return False

    ##14
    def dichoPhoto(d,photos):
        a=0
        b=len(T)-1
        while a < b:
            m=(a+b)//2
            if x==T[m][1]:
                return True
            elif x<T[m][1]:
                b=m
            else:
                a=m
        return False

    ##15
    def nomPatients(images):
        noms=[]
        for key in images:
            n = images[key][2]
            if n not in noms:
                noms.append(n)
        return noms

    ##16
    def nombreDate(images,date):
        i = 0
        for key in images:
            if images[key][1]==date:
                i = i+1
        return i

    ##17
    def fracture(images):
        lab = []
        for key in images:
            l = images[key][3]
            f = (images[key][4]=='FRACTURE')
            if f and l not in lab:
                lab.append(l)
        return lab

    images ={
    109:[2.9 ,20221223 , "DUKIC","OCEANA","",""],
    203:[1.2 ,20221005 ,"MOING","RADIO1","FRACTURE", "TROUSSEAU"],
    405:[6.9 ,20230178 ,"KARL","RADIO2","ARTHROSE", "JENNER"],
    108:[4.1 ,20230206 ,"DUKIC","OCEANA","FRACTURE","PARE"],
    406:[2.0 ,20230612 ,"KARL", "RADIO2", "TENDINITE", "JENNER"]}

Archives

Ces documents ne concernent pas mes étudiants actuels, mais peuvent continuer d'intéresser certaines personnes.