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

 

In general, no offence to the developers of MQL, but the number of math functions https://docs.mql4.com/ru/math

is shamefully small in my opinion, as it is in VB. And the definitions of some of them, like MathFloor, are murky.

-

Take MathMax function, there are only 2 arguments. And if I need 10 or 20, then what does that turn into?

Here's what it looks like in VB with my module:

-

x=max(x1...x20) 'finds the maximum value of 20 variables;

x=max(x1, y, z, p) 'finds the maximum value of 4 variables;

 
MaStak >>:

А вобще, какой то грек сказал что Pi=66/21

The Greek must have said 22/7 (the same as 66/21).

More accurate would be 355/113 (accuracy is 3*10^(-7) ).

The next best fraction is already 103993/ 33102 (accuracy on the order of 6*10^(-10) ).

2 Richie: Well, you had to finish the VB as well. So, why are you going after the Metacquotes then?

 
Gentlemen, get creative at last! The point is not to use this program to find pi, but to decipher how the program did it. Read the subject: "...brain-training problems...". This program is from the "Fun with C" series. There is a contest for composing the most obscure and mysterious C algorithms. You have the source code and the result, but you need to figure out the principle of operation. The algorithm itself is the task to be solved. It needs to be "cracked". This requires you to "break" your brain.
 

Take a joke


 
Mischek писал(а) >>

Take a joke

Mischek, we're former postgraduates, we're solving 8th grade problems, not 11th :)

Poor kids.

 
C-4 >>: Сам алгоритм - это и ест задача для решения. Его надо "взломать". Для этого требуется "поломать" свой мозг.

There you go, I suspected it was a problem...

OK, let's see.

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);
}

Let's deal with the first loop,

   for(; b- c;) f[ b++]= a/5;

The loop is executed as long as expression b - c is evaluated as true. What is true in C? Anything not zero, it seems. So, the loop increasing b from zero and filling array f[] is executed till b equals to c, i.e. till 2800. Array f[] is filled with the same numbers 10000/5 = 2000.

Not much wrong so far?

 

There's only one way to calculate pi anyway, and the rest is a mashka in a different skirt, or part of a mashka :)

 
Mathemat >>:

Ну вот, подозревал ведь, что это задачка...

ОК, смотрим.

Разбираемся с первым циклом,

Цикл выполняется до тех пор, пока b - c = true. Что такое true в Си? Кажись, любой не нуль. Значит, цикл увеличения b от нуля и заполнения массива f[] выполняется до тех пор, пока b не сравняется с с, т.е. до 2800. Массив f[] заполняется одинаковыми числами 10000/5 = 2000.

Пока не сильно ошибся?

Let's have a crack at it.

Right so far. Let's keep watching.

 

But further on it's not clear. Condition d=0 in the first header (outer loop) is bothering me somehow. Is it always true?

 

Next, a nested loop. We rewrite it:

for( ; g= c*2; )
{
d=0;
   for( b= c; -- b; d*= b)
{
d += f[ b] * a;
g
--;
 f[ b] = d % g;
 d /= g;
g--;
}
c-=14;
printf("%.4d", e+ d/ a);
e= d% a;
}
The order is particularly important here.  Check I haven't lied yet? 
Then we move on.

// actually speaking for(; g=c*2; ) would look much better in this edition: for( g=c*2; g !=0; )