diff --git a/module2/exo1/toy_notebook_fr.ipynb b/module2/exo1/toy_notebook_fr.ipynb index ea1990f5d74c95524f4748a65f8b7cdc47d589dd..06ae3e830892f678e2eba9e368ad992e225a8d61 100644 --- a/module2/exo1/toy_notebook_fr.ipynb +++ b/module2/exo1/toy_notebook_fr.ipynb @@ -1,13 +1,25 @@ { "cells": [ { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ - "## Méthode des aiguilles de Buffon\n", + "import random\n", + "import math\n", "\n", - "Pour en savoir plus : \n", - "[Expérience des aiguilles de Buffon (Wikipedia)](https://fr.wikipedia.org/wiki/Aiguille_de_Buffon)" + "def buffon_needle(n_drops=100000):\n", + " hits = 0\n", + " for _ in range(n_drops):\n", + " y = random.random()\n", + " theta = random.uniform(0, math.pi / 2)\n", + " if y <= (math.sin(theta) / 2):\n", + " hits += 1\n", + " return (2 * n_drops) / hits\n", + "\n", + "pi_est = buffon_needle()\n", + "print(f\"Estimation de π par la méthode de Buffon : {pi_est}\")\n" ] } ],