From 53b31bea266fa283c55fa027d81c896205f484fb Mon Sep 17 00:00:00 2001 From: kosipov Date: Sat, 17 Oct 2026 08:47:16 +0200 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20lec1/mc.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lec1/mc.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 lec1/mc.py diff --git a/lec1/mc.py b/lec1/mc.py new file mode 100644 index 0000000..d3f4ae9 --- /dev/null +++ b/lec1/mc.py @@ -0,0 +1,12 @@ +import random +def count_hits(n_points, seed): + """Сколько случайных точек из квадрата [0,1]x[0,1] попало в четверть круга.""" + rng = random.Random(seed) # свой генератор у каждой порции + hits = 0 + for _ in range(n_points): + x, y = rng.random(), rng.random() + if x * x + y * y <= 1.0: + hits += 1 + return hits +def estimate_pi_serial(n_points): + return 4 * count_hits(n_points, seed=0) / n_points