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

 
Mischek:

They won't. The worms will also have bulging eyes. And that's a deterrent.

Oh, man. You're off the hook. A real self-promoting professional.

 

The hockey players didn't want to let go. In the dumb hope of our yawning, I wrote an overkill script. Also says "doesn't exist."

Maybe I yawned in the script? Those who wish may check it.

// Fixed the script. It was a non-critical fault. The result remains the same.

Files:
hockey_1.mq5  2 kb
 
MetaDriver:

The hockey players didn't want to let go. In the dumb hope of our yawning, I wrote an overkill script. Also says "doesn't exist."

Maybe I yawned in the script? Those who wish may check it.

// Fixed the script. It was a non-critical fault. The result remains the same.

I did the same thing afterwards. The answer is the same! :)))
 
MaxZ:
I did the same thing afterwards. The answer is the same! :)))
Show me the source code, if you don't mind. I am interested in your algorithm. You can send it to me in person.
 

Algorithm head-on. Wrote without thinking (3-5 minutes). Takes a long time to count! :D

for (int A6 = 1; A6 <= 6; A6++)
for (int A5 = 1; A5 <= 6; A5++)
for (int A4 = 1; A4 <= 6; A4++)
for (int A3 = 1; A3 <= 6; A3++)
for (int A2 = 1; A2 <= 6; A2++)
for (int A1 = 1; A1 <= 6; A1++)
for (int B6 = 1; B6 <= 6; B6++)
for (int B5 = 1; B5 <= 6; B5++)
for (int B4 = 1; B4 <= 6; B4++)
for (int B3 = 1; B3 <= 6; B3++)
for (int B2 = 1; B2 <= 6; B2++)
for (int B1 = 1; B1 <= 6; B1++)
   if (A6 != A5 && A6 != A4 && A6 != A3 && A6 != A2 && A6 != A1
                && A5 != A4 && A5 != A3 && A5 != A2 && A5 != A1
                            && A4 != A3 && A4 != A2 && A4 != A1
                                        && A3 != A2 && A3 != A1
                                                    && A2 != A1
    && B6 != B5 && B6 != B4 && B6 != B3 && B6 != B2 && B6 != B1
                && B5 != B4 && B5 != B3 && B5 != B2 && B5 != B1
                            && B4 != B3 && B4 != B2 && B4 != B1
                                        && B3 != B2 && B3 != B1
                                                    && B2 != B1
    && A6 != B6 && A5 != B5 && A4 != B4
    && A3 != B3 && A2 != B2 && A1 != B1)
   {
      int A = A6*100000+A5*10000+A4*1000+A3*100+A2*10+A1;
      int B = B6*100000+B5*10000+B4*1000+B3*100+B2*10+B1;
      if (MathMod(A, B) == 0)
         Print(A6,A5,A4,A3,A2,A1,"/",B6,B5,B4,B3,B2,B1,"=",A/B);
   }

P.S.: then I realized, that it would be possible to make iterations on B-arrays much less...

 
Got it, thanks!
 
MaxZ:

Algorithm head-on. Wrote without thinking (3-5 minutes). Takes a long time to count! :D

P.S.: then I realized, that iterations over B-arrays could be much less...

I'm curious to know how and to what degree this enumeration could be optimized.

Here I have ~875 ms on a slow machine. (you have 17516 ms).

How do I twist it up another ten times faster?

I see two options: (1) cut off unnecessary overshoot, (2) speed up validation.

What are your ideas?

// I'm inviting those who would like to. It will do for the next problem.

 
MetaDriver:

//I'm inviting volunteers. It will be good for the next task.

About the task, I was thinking the same thing when I was writing the code! :))) I wanted to suggest it. But disappeared, as I had to create a new topic. How to speed up code, I know (though, not very nice will turn out). But I want not just speed it up, but also make it beautiful!


MetaDriver:

Vapchet interesting, how and to what degree this overshoot can be optimized.

My machine is terrible too... I cannot test a complex Expert Advisor, while a simple one can be optimized for a long time without any complications! :D


MetaDriver:

Here I have it counts ~875 ms on a slow machine. (You have 17516 ms).

How do I twist it up another ten times faster?

I see two options: (1) cut off unnecessary overshoot, (2) speed up validation.

What are your ideas?

I think if you cut out the extra overkill, the execution time will come close to Your result (I looked carefully at the difference in numbers and thought "unlikely")! About the idea, keep thinking.

 

And accelerate My code can be broken down if, consisting of a complex 36-entry check condition, into 36 ifs with a simple condition! :)))

I think the code will speed up considerably, although to know for sure you need to understand machine instructions, which are the result of compilation.

And in general, the topic of performance has always worried me just as much as anything else.

 
MaxZ: And in general, the topic of performance has always worried me just as much as anything else.
I don't like to use continue and break operators, but maybe they can help you, especially if you use 36x if in mql, it may not work.
Reason: