Skip to content

Instantly share code, notes, and snippets.

@tallpeak
Created March 16, 2024 02:41
Show Gist options
  • Save tallpeak/5558b2f02429688fe5c24b9fa3100632 to your computer and use it in GitHub Desktop.
Save tallpeak/5558b2f02429688fe5c24b9fa3100632 to your computer and use it in GitHub Desktop.
digits of pi
import System.Environment
pidigits digits = sum (map piterm [1..(digits - digits `div` 5)]) where
kk = 10 ^ digits
piterm k = kk * 16*(-1)^(k+1)`div`((2*k-1)*5^(2*k-1)) - kk * 4*(-1)^(k+1)`div`((2*k-1)*239^(2*k-1))
main = do
args <- getArgs
let digits :: Integer = read (head args)
print $ pidigits digits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment