[Archive!] Pure mathematics, physics, chemistry, etc.: brain-training problems not related to trade in any way - page 235

 

Don't confuse operand with operation! In our case.

d+=f[b]*a,f[b]=d%--g,d/=g--,--b

All four of them are operations, not operands!

MetaDriver, I don't believe that all but one condition must be discarded. It's not that simple, it's Pi. And anyway, you're boring me with your recursion...

By the way, here is the very first loop that can be checked with the e-compiler along with outputting all the necessary debugging information. C-4 says that the loop will be executed only once (why even once?), while it seems to me that it will be executed many times.

 
Mathemat >>:

Дык операнд, а не операция!

from Strausrup ("The C++ Programming Language", chapter "Reference Manual", section 14 (Summary of Syntax)):

| выражение:

| терм

| выражение бинарная_операция выражение

| выражение ? выражение : выражение

| список выражений

| список выражений:

| выражение:

| список_выражений, выражение


In blue, I highlighted what to look at.

 
Mathemat >>:

Дык не путай операнд и операцию! В нашем случае

все четыре - операции, а не операнды!

1) MetaDriver, не верю, что все условия окромя одного придецца отбросить. Не такое оно простое, это Pi. И вообще, запылил мне мозги своей рекурсией...

Кстати, вот самый первый цикл можно и проверить, у кого компилятор е, вместе с выводом нужной отладочной инфы. С-4 говорит, что цикл выполнится только 1 раз (а почему даже 1 раз-то выполнится?), а мне кажется, что много раз.

You'll have to do it!

Look up some more descriptions of the comma operator on the web. To your complete satisfaction (:floating arrow:).

 
Mathemat >>:

1) Кстати, вот самый первый цикл можно и проверить, у кого компилятор е, вместе с выводом нужной отладочной инфы.

2) С-4 говорит, что цикл выполнится только 1 раз (а почему даже 1 раз-то выполнится?), а мне кажется, что много раз.

That would be nice. I've got some, but I don't want to unload memory for VS.

(I have a lot of programs running, all the memory is full. I'm still working on the stretching and ceiling website:)

 

OK, we'll wait until tomorrow. I'll look at the comma operator. The criterion will still be practice - up to the floating needle.

 
Mathemat >>:

Ладно, погодим до завтра. Я посмотрю оператор запятой. Критерием все равно будет практика.

OK, let's do it tomorrow. :)

 
 

I couldn't resist making a project in the studio. After the next reform (see below) the code works:
int a=10000, b, c=2800, d, e, f[2801], g;

int _tmain(int argc, _TCHAR* argv[]) // Вполне заменяет классический main()
{
   while(( b- c)!=0)  
   {
     f[ b++]= a/5;
   }
   while( g= c*2)
   {
      for( b= c; d+= f[ b]* a, f[ b]= d%-- g, d/= g--,-- b; d*= b);
      
      c-=14;
      printf("%.4d", e+ d/ a);
      e= d% a;
  
      d=0;
  }
   getch(); // Добавил, чтоб тормозить окно от преждевременного захлопывания.
return 0;
}
Next, I'm going to get rid of the last for'a, also replacing it with while.  
Then we can slowly deal with the algorithm, replacing the identifiers with more meaningful ones along the way.

 
C-4 >>:

int a=10000,b,c=2800,d,e,f[2801],g;
int main(void){
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);
}

int a=10000, c=2800, b, d, e, g;
int f[2801];

int main(int argc, char* argv[])
{

for (;(b-c)!=0;b++)
{
f[b]=a/5;
}


for(d=0;c>0;)
{
g=c*2-1;
e=d%a;
for(b=c; b>0;)
{
d=d*b;
d=d+f[b]*a;
f[b]=d%g;
d=d/g;
g=g-2;
b--;
}

printf("%.4d",e+d/a);
c=c-14;
}
return 0;
}

It worked !!!
 

And what, Pi comes out, does it?

Reason: