From 80b3280a83cb82c2ab46a6b38c280f7abbe9ed48 Mon Sep 17 00:00:00 2001 From: ermakov-ad Date: Fri, 6 Oct 2023 15:14:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20=C2=AB?= =?UTF-8?q?2=5Fhw=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First version. Results of other part will be added later --- 2_hw/results.xlsx | Bin 0 -> 13503 bytes 2_hw/with_numpy.py | 24 ++++++++++++++++++++++++ 2_hw/with_typing_hints.py | 30 ++++++++++++++++++++++++++++++ 2_hw/without_typing_hints.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 2_hw/results.xlsx create mode 100644 2_hw/with_numpy.py create mode 100644 2_hw/with_typing_hints.py create mode 100644 2_hw/without_typing_hints.py diff --git a/2_hw/results.xlsx b/2_hw/results.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..d71b34d63453ad84a72af0985874a8053f5c238c GIT binary patch literal 13503 zcmeHuMPM9B(ykb6QHv}li!3IKnVA`FF*7rxEk>)wWHB>Y7Be$i%-mvl^33kejA!0; zFaOq|s=7MktIWutjEs_(f`mc`g8_pB0|O%lOQ*54u>c1HLxBbZLj!|@&=Rt-b~Lhf z)Khk|HFD6QbG5Q0%7%iV%mjmYY5%|D|1bwi;yYwJ84!X`#9M?CsLiYG_~A+yKYjy{ zGZGMy9^=r;WV7QgE^Zhb2!1UQJjhePy?<_Ra3-(TF{q-2ni@&8)c&Lnqsp0gRAhKE zxbu*1gcYRno&7c0B4pM4<(+xelE=4CRkVpEk>h-}kyXK>AAWGFFBEE<3g^yNtn2pG zs)M)Ve?D$-WcB~-X8C^3@f8>tv~QuR0>j`3w8kH!_@JQ=u{}&ytRbhC0`SOqSiweGe(NR5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pmin = -2.5, pmax = 1.5, qmin = -2, qmax = 2, + ppoints = 200, qpoints = 200, max_iterations = 300, infinity_border= 100): + + image = np.zeros((ppoints, qpoints)) + + for ip, p in enumerate(np.linspace(pmin, pmax, ppoints)): + for iq, q in enumerate(np.linspace(qmin, qmax, qpoints)): + c = p + 1j * q + z = 0 + for k in range(max_iterations): + z = z ** 2 + c + if abs(z) > infinity_border: + + image[ip, iq] = 1 + break + return image + +tic = time.perf_counter_ns() +image = mandelbrot() +toc = time.perf_counter_ns() +print((toc - tic)/1_000_000_000, "s") \ No newline at end of file diff --git a/2_hw/with_typing_hints.py b/2_hw/with_typing_hints.py new file mode 100644 index 0000000..e5e03b6 --- /dev/null +++ b/2_hw/with_typing_hints.py @@ -0,0 +1,30 @@ +from __future__ import annotations +import time + +def linspace(start, stop, n): + if n == 1: + yield stop + return + h = (stop - start) / (n - 1) + for i in range(n): + yield start + h * i + +def mandelbrot(pmin: float = -2.5, pmax: float = 1.5, qmin: float = -2, qmax: float = 2, + ppoints: int = 200, qpoints: int = 200, max_iterations: int = 300, infinity_border: float = 100) -> list[list[int]]: + + image: list[list[int]] = [[0 for i in range(qpoints)] for j in range(ppoints)] + for ip, p in enumerate(linspace(pmin, pmax, ppoints)): + for iq, q in enumerate(linspace(qmin, qmax, qpoints)): + c: complex = p + 1j * q + z: complex = 0 + for k in range(max_iterations): + z = z ** 2 + c + if abs(z) > infinity_border: + image[ip][iq] = 1 + break + return image + +tic = time.perf_counter_ns() +image = mandelbrot() +toc = time.perf_counter_ns() +print((toc - tic)/1_000_000_000, "s") \ No newline at end of file diff --git a/2_hw/without_typing_hints.py b/2_hw/without_typing_hints.py new file mode 100644 index 0000000..2afccb4 --- /dev/null +++ b/2_hw/without_typing_hints.py @@ -0,0 +1,28 @@ +import time + +def linspace(start, stop, n): + if n == 1: + yield stop + return + h = (stop - start) / (n - 1) + for i in range(n): + yield start + h * i + +def mandelbrot(pmin = -2.5, pmax= 1.5, qmin = -2, qmax= 2, + ppoints = 200, qpoints = 200, max_iterations = 300, infinity_border = 100): + image = [[0 for i in range(qpoints)] for j in range(ppoints)] + for ip, p in enumerate(linspace(pmin, pmax, ppoints)): + for iq, q in enumerate(linspace(qmin, qmax, qpoints)): + c = p + 1j * q + z = 0 + for k in range(max_iterations): + z = z ** 2 + c + if abs(z) > infinity_border: + image[ip][iq] = 1 + break + return image + +tic = time.perf_counter_ns() +image = mandelbrot() +toc = time.perf_counter_ns() +print((toc - tic)/1_000_000_000, "s") \ No newline at end of file