Last active
November 16, 2026 21:04
-
-
Save bitwombat/367605ba1384625ff89e5f94979de037 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/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