Skip to content

Instantly share code, notes, and snippets.

@bitwombat
Last active November 16, 2026 21:04
Show Gist options
  • Select an option

  • Save bitwombat/367605ba1384625ff89e5f94979de037 to your computer and use it in GitHub Desktop.

Select an option

Save bitwombat/367605ba1384625ff89e5f94979de037 to your computer and use it in GitHub Desktop.
#!/bin/env python
# Generates pi using John Wallis' formula from the 1650s.
# https://x.com/fermatslibrary/status/2122148109404786988
numerator = 2
denominator = 1
counter = 0
accum = 2
while True:
accum *= numerator/denominator
if counter % 1024 == 0: # To keep terminal CPU usage low
print(accum)
if counter % 2 == 0:
denominator += 2
else:
numerator += 2
counter += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment