#!/usr/bin/env python

# Uses generators instead of normal loops

import time
import sys

num_steps = 1000*1000*10

if len(sys.argv) > 1:
  num_steps = int(sys.argv[1])

print("Calculating PI with:\n  %d slices\n  1 process" % num_steps)

total_sum = 0
step = 1.0 / num_steps

start = time.time()

def slice_area_gen(l):
  for i in l:
    x = (i+0.5)*step
    yield 4.0/(1.0+x*x)

pi = step * sum(slice_area_gen(xrange(num_steps)))

stop = time.time()

print("Obtained value of PI: %.32g\n"
      "Time taken: %g seconds"
      % (pi, stop - start) )




