#include <stdio.h>
int a=10000,b,c=2800,d,e,f[2801],g;
void main()
{
for(;b-c;)f[b++]=a/5;
for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a,
f[b]=d%--g,d/=g--,--b;d*=b);
Thanks.
what does this do?
Hello everyone. I was just wondering if you guys could rewrite the program that I found somewhere to compute pi? I looked over it a million times, and all of these null for statements and commas inside for statements are confusing me(I dont get what they are doing...) If anyone of you can rewrite this for me, well, thanks.
This looks like an entry to an obfuscation contest. If you''re seriously want an algorithm to compute pi, I suggest you keep on searching.
"A society without religion is like a crazed psychopath without a loaded .45"
"A society without religion is like a crazed psychopath without a loaded .45"
const double PI = atan(1) * 4;
See the following site for info on how to calculate everything yourself:
http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibpi.html
#include <stdio.h>//// Overly verbose "de-obfuscation"//// Interestingly, that first line wouldn''t compile on some// compilers because they require declarations to occur before// initializations in the same statement.int a = 10000;int b;int c = 2800;int d;int e;int f[2801];int g;//void main(){ // array intialization: for( ; // no initial condition specified b-c; // when b = c, this evaluates to zero - false ) // increment occurs within loop body { f[b]=a/5; // set bth element to a/5 b = b+1; // increment b }// // determination of pi: for( ; // no intial condition d=0, g=c*2; // comma operator executes both "sub-statements" c-=14 ) // decrement c by 14 { // as before, the comma operator was used to relocate the // loop body to the increment portion of the loop printf("%.4d",e+d/a); e=d%a; // // by now you should be familiar with the comma operator for(b=c; // this loop probably terminates when d evaluates // to zero (? anyone who thinks otherwise, please // post) d+=f[b]*a; // d = d + (f * a)<br></font><br> d*=b)<br> {<br> f[<font color="purple">b</font>]=d%–g; <font color="gray">// g = g - 1; f = remainder of d / g<br></font><br> d/=g–; <font color="gray">// d = d / g; g = g - 1<br></font><br> –b; <font color="gray">// b = b -1<br></font><br> }<br> }<br>} </pre></font></td></tr></table></center><!–ENDSCRIPT–><br><br>The code relies on the comma operator to syntactically place multiple statements in one, but that gets expanded at compile time. It also employs operator precedence, associativity and execution order to concatenate assignments and pre- or post-increments.
quote:Original post by masonium
when I tried it, it didn''t work. I got a whole lot of 0s and a 2
Works for me. I compiled it in Borland C++ 5.0 (I use it for quick compiles since it doesn''t require that you make a project).
[Resist Windows XP''s Invasive Production Activation Technology!]
Ok, I get most of it. Its just this part that I dont get
I dont get how the for statement works. You say that when b=c then "this" evaluates to zero. What evaluates to zero? b-c? If so, then when will this happen, because the loop does not do anything to "c"? Also, when will the loops stop? when b=c? I know my question probably makes no sense, but that is only because I have no clue what this loop does at ALL. NOTE: I am not looking at this for a way to compute pi...just a challenging program that I dont have no clue how to understand. Thanks again.
// array intialization: for( ; // no initial condition specified b-c; // when b = c, this evaluates to zero - false ) // increment occurs within loop body { f[b]=a/5; // set bth element to a/5 b = b+1; // increment b }
I dont get how the for statement works. You say that when b=c then "this" evaluates to zero. What evaluates to zero? b-c? If so, then when will this happen, because the loop does not do anything to "c"? Also, when will the loops stop? when b=c? I know my question probably makes no sense, but that is only because I have no clue what this loop does at ALL. NOTE: I am not looking at this for a way to compute pi...just a challenging program that I dont have no clue how to understand. Thanks again.
b-c is the second parameter to the for loop, so when it evaluates to 0 the for loop terminates, i.e. when b=c in this case
c may not change, but b does
c may not change, but b does
Ohhhhhhhhh!!! Ok, now I get it. With that information given, I have greatly simplified the program to this:
I am so proud of myself
#include <stdio.h>int a=10000,b,c=2800,d,e,f[2801],g;void main(){ while((b-c) != 0) { f[b]=a/5; b = b + 1; } while(true) { d = 0; g=c*2; if(g == 0) break; b = c; while(true) { d= d + f[b]*a; g = g - 1; f[b] = d % g; d = d / g; g = g - 1; --b; if(b == 0) break; d*= b; } c = c - 14; printf("%.4d",e+d/a); e = d % a; }}
I am so proud of myself
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement