From 0612c6ac59e3872d014669c2c6839d2ec54f60df Mon Sep 17 00:00:00 2001 From: newt Date: Wed, 9 Oct 2024 18:02:45 +0100 Subject: [PATCH] feat: pi calculator and chunk array --- languages/python/calculators/pi.py | 12 ++++++++++++ languages/python/chunkArray.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 languages/python/calculators/pi.py diff --git a/languages/python/calculators/pi.py b/languages/python/calculators/pi.py new file mode 100644 index 0000000..eb55d4e --- /dev/null +++ b/languages/python/calculators/pi.py @@ -0,0 +1,12 @@ +import math + +pi = 0 + +for k in range(20): + numerator = (2 ** k) * (math.factorial(k) ** 2) + denominator = math.factorial((2 * k) + 1) + + pi += numerator / denominator + +pi *= 2 +print(pi) diff --git a/languages/python/chunkArray.py b/languages/python/chunkArray.py index a90204d..7206d66 100644 --- a/languages/python/chunkArray.py +++ b/languages/python/chunkArray.py @@ -8,4 +8,4 @@ def chunkArray(array, chunkCount): return chunks -print(chunkArray([1,2,3,4,5,6], 3)) +print(chunkArray([1,2,3,4,5,6], 4))