@sek/

314-Digits

Python

314 Digits of PI.py - Designed to fit on a T Shirt See embedded comment for additional information

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.00543672359307279","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"ZGVmIHBpKCk6CiAgciA9IDQqKDQqYXJjY290KDUpIC0gYXJjY290KDIzOSkpCiAgcmV0dXJuIHN0cihyKVswXSsnLicrc3RyKHIpWzE6LTVdCgpkZWYgYXJjY290KHgpOgogIHRvdGFsID0gcG93ZXIgPSAxMCoqMzE5IC8vIHgKICBkaXZpc29yID0gMQogIHdoaWxlIGFicyhwb3dlcikgPj0gZGl2aXNvcjoKICAgIHBvd2VyID0gLXBvd2VyIC8vIHgqKjIKICAgIGRpdmlzb3IgKz0gMgogICAgdG90YWwgKz0gcG93ZXIgLy8gZGl2aXNvcgogIHJldHVybiB0b3RhbAoKcHJpbnQoIjMxNCBkaWdpdHMgb2YgUGkgIiArIHBpKCkpCgoiIiIKU2hpcnQ6ICQxOS45OTogaHR0cHM6Ly93d3cuYW1hem9uLmNvbS9kcC9CMDdCQkdHOUI1CkZyZWUgc2hpcHBpbmcgZm9yIFByaW1lIG1lbWJlcnMgPSkKCi0tLS0tCgpUaGlzIHB5dGhvbiBjb2RlIHdhcyBjcmFmdGVkIHRvIGJlIHNob3J0IGVub3VnaCB0byBmaXQgb24gYSB0LXNoaXJ0LCBidXQgc3RpbGwgcmVhZGFibGUuCgpSdW5uaW5nIHRoZSBjb2RlIG9uIHRoZSBmcm9udCBvZiB0aGUgc2hpcnQgcHJvZHVjZXMgdGhlIG91dHB1dCBvbiB0aGUgYmFjay4KUHJlc3MgdGhlIHBsYXkgYnV0dG9uIGFib3ZlIHRvIGdlbmVyYXRlIHRoaXMgb3V0cHV0LgoKVGhpcyBhbGdvcml0aG0gd2FzIGRldmVsb3BlZCBpbiAxNzA2ISBGb3IgbW9yZSBpbmZvLCBzZWU6IGh0dHBzOi8vZW4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4*(4*arccot(5) - arccot(239))
  return str(r)[0]+'.'+str(r)[1:-5]

def arccot(x):
  total = power = 10**319 // x
  divisor = 1
  while abs(power) >= divisor:
    power = -power // x**2
    divisor += 2
    total += power // divisor
  return total

print("314 digits of Pi " + pi())

"""
Shirt: $19.99: https://www.amazon.com/dp/B07BBGG9B5
Free shipping for Prime members =)

-----

This python code was crafted to be short enough to fit on a t-shirt, but still readable.

Running the code on the front of the shirt produces the output on the back.
Press the play button above to generate this output.

This algorithm was developed in 1706! For more info, see: https://en.wikipedia.org/wiki/John_Machin
and: https://www.craig-wood.com/nick/articles/pi-machin/

The arccot method uses integer math to calculate an arc cotangent. See here for info on what an ArcCot is: http://reference.wolfram.com/language/ref/ArcCot.html
The 319 on line 6 is the length of the integer to start with (1 followed by 319 zeros) and therefore sets the precision of the end result.
The algorithm ends up with a few incorrect digits at the end of the result - This is why 319 is used instead of 314, and also explains the -5 on line 3 which drops the erroneous digits.

Some sites that can verify the output:
- http://3.141592653.com/
- http://www-groups.dcs.st-and.ac.uk/history/HistTopics/1000_places.html
"""