Let $p \in ]0,1[$. We start from the zero matrix of $\mathcal{M}_n(\mathbb{R})$, denoted $M_0$. For all $k \in \mathbb{N}$, we construct the matrix $M_{k+1}$ from the matrix $M_k$ by scanning through the matrix in one pass and changing each zero coefficient to 1 with probability $p$, independently.
Throughout this question we use the Python language. M denotes a square matrix of order $n$. Its rows and columns are numbered from 0 to $n-1$. The expression $\mathrm{M[i,j]}$ allows access to the element at the intersection of row $i$ and column $j$ and len(M) gives the order of the matrix M.
a) Write a function Somme(M) that returns the sum of the coefficients of the matrix M.
b) Write a function Bernoulli(p) that returns 1 with probability $p$ and 0 with probability $1-p$. You may use the expression random() which returns a real number in the interval $[0,1[$ according to the uniform distribution.
c) Using the function Bernoulli(p), write a function Modifie(M,p) that randomly modifies the matrix M according to the principle described above.
d) Write a function Simulation(n,p) that returns the smallest integer $k$ such that $M_k$ is completely filled starting from a random filling of the zero matrix of order $n$ (which can be obtained by zeros$((n,n))$). It is not required to store the $M_k$.