Skip to content

Instantly share code, notes, and snippets.

@kenreilly
Created March 14, 2025 15:49
Show Gist options
  • Save kenreilly/51a2fd1bf6f731c5256fc4233f221ead to your computer and use it in GitHub Desktop.
Save kenreilly/51a2fd1bf6f731c5256fc4233f221ead to your computer and use it in GitHub Desktop.
import sys
import time
class Spigot:
def write(x) -> None:
sys.stdout.write(str(x))
sys.stdout.flush()
time.sleep(0.1)
def pi() -> int:
i: int = 0
k: int = 2
a: int = 4
b: int = 1
a1: int = 12
b1: int = 4
while True:
p: int = k * k
q: int = 2 * k + 1
k += 1
a, b, a1, b1 = a1, b1, p * a + q * a1, p * b + q * b1
d: int = a / b
d1: int = a1 / b1
while d == d1:
Spigot.write(int(d))
if i == 0:
Spigot.write('.')
a, a1 = 10 * (a % b), 10 * (a1 % b1)
d, d1 = a / b, a1 / b1
i += 1
Spigot.pi()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment