Skip to content

Instantly share code, notes, and snippets.

View test.html
<html>
<head>
<title>How to add source code to Medium</title>
</head>
<body>
</body>
</html>
@CodeDrome
CodeDrome / estimatingpi_1.py
Created Jul 28, 2020
estimatingpi.py part 1
View estimatingpi_1.py
import math
PI_STRING = "3.141592653589793238"
RED = "\x1B[31m"
GREEN = "\x1B[32m"
RESET = "\x1B[0m"
def main():
@CodeDrome
CodeDrome / estimatingpi_2.py
Created Jul 28, 2020
estimatingpi.py part 2
View estimatingpi_2.py
def fractions():
"""
Estimates pi using a selection of increasingly accurate fractions
"""
pi = 22 / 7
print("22/7\n====")
print_as_text(pi)
@CodeDrome
CodeDrome / estimatingpi_3.py
Created Jul 28, 2020
estimatingpi.py part 3
View estimatingpi_3.py
def francois_viete():
"""
Infinite series discovered by French mathematician Francois Viete in 1593
"""
print("Francois Viete\n==============")
iterations = 28
numerator = 0.0
@CodeDrome
CodeDrome / estimatingpi_4.py
Created Jul 28, 2020
estimatingpi.py part 4
View estimatingpi_4.py
def john_wallis():
"""
Infinite product created by English mathematician John Wallis in 1655
"""
print("John Wallis\n===========")
iterations = 1000000
numerator = 2.0
@CodeDrome
CodeDrome / estimatingpi_5.py
Created Jul 28, 2020
estimatingpi.py part 5
View estimatingpi_5.py
def john_machin():
"""
Formula discovered by English astronomer John Machin in 1706
"""
print("John Machin\n===========")
pi = (4.0 * math.atan(1.0 / 5.0) - math.atan(1.0 / 239.0)) * 4.0
@CodeDrome
CodeDrome / estimatingpi_6.py
Created Jul 28, 2020
estimatingpi.py part 6
View estimatingpi_6.py
def gregory_leibniz():
"""
Co-discovered by James Gregory and Gottfried Wilhelm Leibniz
"""
print("Gregory-Leibniz\n===============")
iterations = 400000
denominator = 1.0
@CodeDrome
CodeDrome / estimatingpi_7.py
Created Jul 28, 2020
estimatingpi.py part 7
View estimatingpi_7.py
def nilakantha():
"""
Named after the 15th century Indian mathematician Nilakantha Somayaji
"""
print("Nilakantha\n=========")
iterations = 1000000
multiplier = 1.0
View galtonboard.py
import math
from random import choice
import time
GREEN = "\x1B[94m"
RESET = "\x1B[0m"
class GaltonBoard(object):
View galtonboardview.py
import os
import math
import sys
import time
# ANSI terminal colour codes
RED = "\x1B[91m"
GREEN = "\x1B[92m"
RESET = "\x1B[0m"