Browse Source

Replace ++ in sumPi to shorten summation time.

Josh Bicking 6 years ago
parent
commit
4c14b5760e
1 changed files with 3 additions and 3 deletions
  1. 3 3
      app/Main.hs

+ 3 - 3
app/Main.hs

@@ -30,10 +30,10 @@ hexPi n =
 sumPi :: Integer -> Integer -> Double
 sumPi n x =
   let
-    summation1 = [(fromIntegral ((16^(n-k) `mod` ((8*k)+x)))) / (fromIntegral ((8*k)+x)) | k <- [0..n]]
-    summation2 = [16^^(n-k) / (fromIntegral ((8*k)+x)) | k <- [(n+1)..5000]]
+    summation1 = sum [(fromIntegral ((16^(n-k) `mod` ((8*k)+x)))) / (fromIntegral ((8*k)+x)) | k <- [0..n]]
+    summation2 = sum [16^^(n-k) / (fromIntegral ((8*k)+x)) | k <- [(n+1)..5000]]
   in
-    sum $ summation1 ++ summation2
+    summation1 + summation2
 
 
 -- Get a range of digits.