├── README.md └── pycalc.py /README.md: -------------------------------------------------------------------------------- 1 | # Pi-Calculator 2 | Just run this forever and you'll eventually calculate pi 3 | -------------------------------------------------------------------------------- /pycalc.py: -------------------------------------------------------------------------------- 1 | import random 2 | import math 3 | 4 | 5 | def main(): 6 | inside = 0 7 | total = 0 8 | while True: 9 | x = random.random() 10 | y = random.random() 11 | dist = math.sqrt(x*x+y*y) 12 | if dist < 1: 13 | inside+=1 14 | total+=1 15 | pi = 4.0 * inside / total 16 | print(pi) 17 | 18 | 19 | main() 20 | --------------------------------------------------------------------------------