Skip to content

Instantly share code, notes, and snippets.

View CodeDrome's full-sized avatar

Chris Webb CodeDrome

View GitHub Profile
@CodeDrome
CodeDrome / test.html
Created July 28, 2020 14:45
Test HTML
<html>
<head>
<title>How to add source code to Medium</title>
</head>
<body>
</body>
</html>
@CodeDrome
CodeDrome / estimatingpi_1.py
Created July 28, 2020 14:58
estimatingpi.py part 1
import math
PI_STRING = "3.141592653589793238"
RED = "\x1B[31m"
GREEN = "\x1B[32m"
RESET = "\x1B[0m"
def main():
@CodeDrome
CodeDrome / estimatingpi_2.py
Created July 28, 2020 15:02
estimatingpi.py part 2
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 July 28, 2020 15:14
estimatingpi.py part 3
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 July 28, 2020 15:22
estimatingpi.py part 4
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 July 28, 2020 15:34
estimatingpi.py part 5
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 July 28, 2020 15:41
estimatingpi.py part 6
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 July 28, 2020 15:54
estimatingpi.py part 7
def nilakantha():
"""
Named after the 15th century Indian mathematician Nilakantha Somayaji
"""
print("Nilakantha\n=========")
iterations = 1000000
multiplier = 1.0
@CodeDrome
CodeDrome / galtonboard.py
Created July 29, 2020 08:10
galtonboard.py
import math
from random import choice
import time
GREEN = "\x1B[94m"
RESET = "\x1B[0m"
class GaltonBoard(object):
@CodeDrome
CodeDrome / galtonboardview.py
Created July 29, 2020 08:18
galtonboardview.py
import os
import math
import sys
import time
# ANSI terminal colour codes
RED = "\x1B[91m"
GREEN = "\x1B[92m"
RESET = "\x1B[0m"