This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>How to add source code to Medium</title> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
PI_STRING = "3.141592653589793238" | |
RED = "\x1B[31m" | |
GREEN = "\x1B[32m" | |
RESET = "\x1B[0m" | |
def main(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fractions(): | |
""" | |
Estimates pi using a selection of increasingly accurate fractions | |
""" | |
pi = 22 / 7 | |
print("22/7\n====") | |
print_as_text(pi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def francois_viete(): | |
""" | |
Infinite series discovered by French mathematician Francois Viete in 1593 | |
""" | |
print("Francois Viete\n==============") | |
iterations = 28 | |
numerator = 0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def john_wallis(): | |
""" | |
Infinite product created by English mathematician John Wallis in 1655 | |
""" | |
print("John Wallis\n===========") | |
iterations = 1000000 | |
numerator = 2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gregory_leibniz(): | |
""" | |
Co-discovered by James Gregory and Gottfried Wilhelm Leibniz | |
""" | |
print("Gregory-Leibniz\n===============") | |
iterations = 400000 | |
denominator = 1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def nilakantha(): | |
""" | |
Named after the 15th century Indian mathematician Nilakantha Somayaji | |
""" | |
print("Nilakantha\n=========") | |
iterations = 1000000 | |
multiplier = 1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
from random import choice | |
import time | |
GREEN = "\x1B[94m" | |
RESET = "\x1B[0m" | |
class GaltonBoard(object): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import math | |
import sys | |
import time | |
# ANSI terminal colour codes | |
RED = "\x1B[91m" | |
GREEN = "\x1B[92m" | |
RESET = "\x1B[0m" |
OlderNewer