fork download
  1. binPis' = let
  2. next ( x@( n, p, q , p', q' ) ) = let
  3. p'' = ( 2*n-1 ) * p' + ( n-1 ) ^2 * p
  4. q'' = ( 2*n-1 ) * q' + ( n-1 ) ^2 * q
  5. ( f, f' ) = ( div p q, div p' q' )
  6. g = foldl1 gcd [ p', q', p'', q'' ]
  7. [ np', nq', np'', nq'' ] = map ( flip div g ) [ p',q',p'',q'' ]
  8. in if f == f'
  9. then ( f,x ) : next ( n + 1, 2*(np'- f * nq') , nq', 2*(np'' - f * nq''), nq'' )
  10. else next ( n + 1, p',q', p'', q'' )
  11. in map fst $ next ( 2, 2, 3, 5, 3 )
  12.  
  13. binPis'' = zipWith (+)
  14. ( zipWith ( * ) binPis' $ iterate (*(-1)) 1 )
  15. ( concat $ repeat [ 0, 1 ] )
  16.  
  17. main = do
  18. print $ take 100 binPis''
  19. print $ sum $ take 100 $ zipWith ( * ) [ 4*(-0.5)^n | n<-[0..] ] $ map ( fromInteger ) $ binPis''
  20.  
Success #stdin #stdout 0.01s 5556KB
stdin
Standard input is empty
stdout
[1,1,1,0,1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,1,0,1,1,1,0,0,1,1,1,0,0,0,1,1,0,0,1,1,1,0,1,0,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,1,1,0,1,0,0,1,1,1,1,0,0,1,1,1,0,0,1,0,0]
3.141592653589793