From a3b6ecf098286977ca0f9aa5dadca40cd8699c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kn=C3=BCttel?= Date: Wed, 24 Oct 2018 17:15:50 +0200 Subject: [PATCH] Added Exercise 3 --- ex_01_03.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 ex_01_03.py diff --git a/ex_01_03.py b/ex_01_03.py new file mode 100644 index 0000000..ee95a1e --- /dev/null +++ b/ex_01_03.py @@ -0,0 +1,14 @@ +#!/usr/bin/python3 + +import math + +def bailey_borwein_plouffe_pi(n): + result = 0 + for k in range(n): + result += (1/16)**k * ( 4/(8*k + 1) - 2/(8*k + 4) - 1/(8*k + 5) - 1/(8*k + 6)) + + return result + +if( __name__ == "__main__"): + + assert bailey_borwein_plouffe_pi(1000) == math.pi