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

前端 未结 3 527
北恋
北恋 2021-01-01 04:23

This C program is just 143 characters long!

But it “decompresses” into the first 10,000 digits of Pi.

//  Created by cheeseMan on 3         


        
3条回答
  •  一个人的身影
    2021-01-01 05:03

    It can be written as

    long a[35014];
    long b;
    long c=35014;
    long d;
    long e;
    long f=1e4;
    long g;
    long 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;
            }
        }
    }
    

    In other words it's double for loop

提交回复
热议问题