From 2de543b17f15543b23b15d66ae7f1cb3eacf6ea6 Mon Sep 17 00:00:00 2001 From: a49c585c4fe7205185de4c52fe2e58c3 Date: Sun, 2 Nov 2025 20:08:42 +0000 Subject: [PATCH] no commit message --- module2/exo1/toy_notebook_fr.ipynb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/module2/exo1/toy_notebook_fr.ipynb b/module2/exo1/toy_notebook_fr.ipynb index ea1990f..06ae3e8 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" ] } ], -- 2.18.1