Created
March 14, 2026 14:03
-
-
Save aciceri/5ff4cf5283aebbaffdaa78cd85cbacde to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| nixpkgs ? <nixpkgs>, | |
| system ? builtins.currentSystem | |
| }: let | |
| pkgs = import nixpkgs { inherit system; }; | |
| inherit (pkgs) lib; | |
| # Bailey–Borwein–Plouffe formula | |
| piDigit = n: pkgs.runCommand "pi-${toString n}" {} '' | |
| n=${toString n}; ${lib.getExe pkgs.python314} -c " | |
| from decimal import Decimal,getcontext | |
| getcontext().prec=$n+20 | |
| pi=sum((Decimal(4)/(8*k+1)-Decimal(2)/(8*k+4)-Decimal(1)/(8*k+5)-Decimal(1)/(8*k+6))/Decimal(16)**k for k in range($n*2+50)) | |
| print(str(pi).replace('.',\"\")[$n]) | |
| " > $out | |
| ''; | |
| digits = 100; | |
| pi = pkgs.runCommand "pi" {} '' | |
| cat ${lib.concatMapStringsSep " " (n: piDigit n) (lib.range 0 digits)} | tr -d '\n' > $out | |
| ''; | |
| in { | |
| inherit pi; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment