spigot-algorithm

Implementing the Spigot algorithm for π (pi)

可紊 提交于 2019-12-03 17:47:51
问题 I'm having a hard time understanding the Spigot algorithm for π (pi) found here at the bottom of the page. I'm getting lost at the bottom of part 2 "Put A into regular form", I'm not exactly sure how to implement this in C (or any language really) 回答1: #include <math.h> #include <stdio.h> #define N 100 int len = floor(10 * N/3) + 1; int A[len]; for(int i = 0; i < len; ++i) { A[i] = 2; } int nines = 0; int predigit = 0; for(int j = 1; j < N + 1; ++j) { int q = 0; for(int i = len; i > 0; --i) {

Implementing the Spigot algorithm for π (pi)

旧城冷巷雨未停 提交于 2019-12-03 06:30:51
I'm having a hard time understanding the Spigot algorithm for π (pi) found here at the bottom of the page. I'm getting lost at the bottom of part 2 "Put A into regular form", I'm not exactly sure how to implement this in C (or any language really) #include <math.h> #include <stdio.h> #define N 100 int len = floor(10 * N/3) + 1; int A[len]; for(int i = 0; i < len; ++i) { A[i] = 2; } int nines = 0; int predigit = 0; for(int j = 1; j < N + 1; ++j) { int q = 0; for(int i = len; i > 0; --i) { int x = 10 * A[i-1] + q*i; A[i-1] = x % (2*i - 1); q = x / (2*i - 1); } A[0] = q%10; q = q/10; if (9 == q)

Can anyone make heads or tales of this spigot algorithm code Pitiny.c

给你一囗甜甜゛ 提交于 2019-11-30 10:15:55
This C program is just 143 characters long! But it “decompresses” into the first 10,000 digits of Pi . // Created by cheeseMan on 30/11/13. long a[35014],b,c=35014,d,e,f=1e4,g,h; int main(int argc, const char * argv[]) { for(;(b=c-=14); h=printf("%04ld",e+d/f)) for(e=d%=f;(g=--b*2);d/=g) d=d*b+f*(h?a[b]:f/5), a[b]=d%--g; } I was doing some research on loss-less compression algorithms, still no luck yet, when I came across this pitiny.c . The weird thing is that it compiles successfully no errors or bugs, but like i said i cannot make heads or tales of the code, even its syntax. I just would

Can anyone make heads or tales of this spigot algorithm code Pitiny.c

与世无争的帅哥 提交于 2019-11-29 15:22:16
问题 This C program is just 143 characters long! But it “decompresses” into the first 10,000 digits of Pi . // Created by cheeseMan on 30/11/13. long a[35014],b,c=35014,d,e,f=1e4,g,h; int main(int argc, const char * argv[]) { for(;(b=c-=14); h=printf("%04ld",e+d/f)) for(e=d%=f;(g=--b*2);d/=g) d=d*b+f*(h?a[b]:f/5), a[b]=d%--g; } I was doing some research on loss-less compression algorithms, still no luck yet, when I came across this pitiny.c . The weird thing is that it compiles successfully no