:-) if you don't try to keep the order, the time isO(1), the total number of steps of all the loops= array size
too lazy to code :-)
1. Search for first 3 from left to right.
2. if found, then look for a non-triple from right to left, copy it to the place of the 3.
continue until 1,2 have intersected, trim the array by the number of copies.
Ideally, it is exactly 1/2 of "bubble sorting" :-) If instead of copying, you make a swap, the output will be a partially ordered array (all 3-thirds moved to the right)
Total number of steps of all loops=array size is O(n) complexity. If the input array is sorted, the given problem is solved through binary search. The complexity is O(log(n)) in the average case and O(n) in the worst case.
It's quite compact and even works properly. Kudos to Peter. But in terms of speed it comes second from the end. Or first place from the end, if you don't count the original, completely unusable by speed variant of the owner of this thread.
2018.11.1403:26:49.182 ArrayDeleteValue (BTCUSD,M15) вариант Pastushak: Контрольная сумма = 496575839; элементов - 998974; время выполнения = 131158 микросекунд
2018.11.1403:26:49.185 ArrayDeleteValue (BTCUSD,M15) вариант Korotky: Контрольная сумма = 496575839; элементов - 998974; время выполнения = 2431 микросекунд
2018.11.1403:26:49.188 ArrayDeleteValue (BTCUSD,M15) вариант Fedoseev: Контрольная сумма = 496575839; элементов - 998974; время выполнения = 1809 микросекунд
2018.11.1403:26:49.190 ArrayDeleteValue (BTCUSD,M15) вариант Semko: Контрольная сумма = 496575839; элементов - 998974; время выполнения = 785 микросекунд
2018.11.1403:26:49.194 ArrayDeleteValue (BTCUSD,M15) вариант Pavlov: Контрольная сумма = 496575839; элементов - 998974; время выполнения = 2839 микросекунд
2018.11.1403:26:49.199 ArrayDeleteValue (BTCUSD,M15) вариант Nikitin: Контрольная сумма = 496575839; элементов - 997971; время выполнения = 4049 микросекунд
2018.11.1403:26:49.204 ArrayDeleteValue (BTCUSD,M15) вариант Vladimir: Контрольная сумма = 496575839; элементов - 998974; время выполнения = 3888 микросекунд
2018.11.1403:26:49.212 ArrayDeleteValue (BTCUSD,M15) вариант Peter: Контрольная сумма = 496575839; элементов - 998974; время выполнения = 7597 микросекунд
It's not that I'm lazy at all, but MT is only on VDSs and you don't experiment on them.
about that :
+- 1 :-) I'll be back from the countryside in a couple of days, I'll check it out...
ps. in addition, in the code extra input to the loop at the end...a trifle, but can be removed
Bravo! After correcting a couple of errors you may have knocked me off the pedestal even without using ArrayCopy. Checkmate. :))
template <typename T>
int arrayFilter3(T &arr[], const T x) // вариан Kuznetsov
{
int i=0;
int j=ArraySize(arr)-1;
for(;;) {
while(arr[i]!=x && i<j) i++;
while(arr[j]==x && i<j) j--;
if (i<j) {
arr[i++]=arr[j--];
} elsebreak;
}
ArrayResize(arr,j+1);
return j+1;
}
2018.11.1403:48:29.572 ArrayDeleteValue (USDRUB,M1) вариант Pastushak: Контрольная сумма = 496206996; элементов - 999002; время выполнения = 131929 микросекунд
2018.11.1403:48:29.576 ArrayDeleteValue (USDRUB,M1) вариант Korotky: Контрольная сумма = 496206996; элементов - 999002; время выполнения = 2411 микросекунд
2018.11.1403:48:29.579 ArrayDeleteValue (USDRUB,M1) вариант Fedoseev: Контрольная сумма = 496206996; элементов - 999002; время выполнения = 1839 микросекунд
2018.11.1403:48:29.581 ArrayDeleteValue (USDRUB,M1) вариант Semko: Контрольная сумма = 496206996; элементов - 999002; время выполнения = 782 микросекунд
2018.11.1403:48:29.585 ArrayDeleteValue (USDRUB,M1) вариант Pavlov: Контрольная сумма = 496206996; элементов - 999002; время выполнения = 2813 микросекунд
2018.11.1403:48:29.590 ArrayDeleteValue (USDRUB,M1) вариант Nikitin: Контрольная сумма = 496206996; элементов - 997969; время выполнения = 4200 микросекунд
2018.11.1403:48:29.596 ArrayDeleteValue (USDRUB,M1) вариант Vladimir: Контрольная сумма = 496206996; элементов - 999002; время выполнения = 3597 микросекунд
2018.11.1403:48:29.604 ArrayDeleteValue (USDRUB,M1) вариант Peter: Контрольная сумма = 496206996; элементов - 999002; время выполнения = 7684 микросекунд
2018.11.1403:48:29.606 ArrayDeleteValue (USDRUB,M1) вариант Kuznetsov: Контрольная сумма = 496206996; элементов - 999002; время выполнения = 681 микросекунд
Bravo! After correcting a couple of errors, you've knocked me off the pedestal even without using ArrayCopy. Checkmate. :))
Although not exactly so, because the output array is quite different - already mixed. But it's cool anyway!
Of course, if we are dealing with quotes, this will not work. I'm on the podium again. ))
I've changed the way of calculating the checksum. No longer the simple sum of all elements, but the sum is (element value)/(element number). And this is what I got:
2018.11.1404:20:26.063 ArrayDeleteValue (USDRUB,M1) вариант Pastushak: Контрольная сумма = 7090.600736767353; элементов - 999003; время выполнения = 132291 микросекунд
2018.11.1404:20:26.067 ArrayDeleteValue (USDRUB,M1) вариант Korotky: Контрольная сумма = 7090.600736767353; элементов - 999003; время выполнения = 2322 микросекунд
2018.11.1404:20:26.071 ArrayDeleteValue (USDRUB,M1) вариант Fedoseev: Контрольная сумма = 7090.600736767353; элементов - 999003; время выполнения = 1831 микросекунд
2018.11.1404:20:26.074 ArrayDeleteValue (USDRUB,M1) вариант Semko: Контрольная сумма = 7090.600736767353; элементов - 999003; время выполнения = 773 микросекунд
2018.11.1404:20:26.079 ArrayDeleteValue (USDRUB,M1) вариант Pavlov: Контрольная сумма = 7090.600736767353; элементов - 999003; время выполнения = 2879 микросекунд
2018.11.1404:20:26.085 ArrayDeleteValue (USDRUB,M1) вариант Nikitin: Контрольная сумма = 7093.903216084301; элементов - 998017; время выполнения = 3605 микросекунд
2018.11.1404:20:26.090 ArrayDeleteValue (USDRUB,M1) вариант Vladimir: Контрольная сумма = 7090.600736767353; элементов - 999003; время выполнения = 3622 микросекунд
2018.11.1404:20:26.100 ArrayDeleteValue (USDRUB,M1) вариант Peter: Контрольная сумма = 7090.600736767353; элементов - 999003; время выполнения = 7252 микросекунд
2018.11.1404:20:26.102 ArrayDeleteValue (USDRUB,M1) вариант Kuznetsov: Контрольная сумма = 7085.49357433088; элементов - 999003; время выполнения = 691 микросекунд
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Compare the 2 code variants on the same ToR:
и:
Could this have been written by the same person with a little over an hour apart? The handwriting is questionable )Alexei, you're killing young talent...
This marketer hasn't been able to start selling for 5 years...and you're saying he's even worse as a programmer
Sorry, I didn't mean to kill you.
:-) if you don't try to keep the order, the time isO(1), the total number of steps of all the loops= array size
too lazy to code :-)
1. Search for first 3 from left to right.
2. if found, then look for a non-triple from right to left, copy it to the place of the 3.
continue until 1,2 have intersected, trim the array by the number of copies.
Ideally, it is exactly 1/2 of "bubble sorting" :-) If instead of copying, you make a swap, the output will be a partially ordered array (all 3-thirds moved to the right)
Total number of steps of all loops=array size is O(n) complexity.
If the input array is sorted, the given problem is solved through binary search.
The complexity is O(log(n)) in the average case and O(n) in the worst case.
Still got the hang of Peter's version.
It's quite compact and even works properly. Kudos to Peter.
But in terms of speed it comes second from the end. Or first place from the end, if you don't count the original, completely unusable by speed variant of the owner of this thread.
How did you test it?
How have you been testing?
Study the code.
It's bad when you're too lazy to code.
It's not that I'm lazy at all, but MT is only on VDSs and you don't experiment on them.
about that :
+- 1 :-) I'll be back from summer camp in a couple of days, I'll check it out...
ps. in addition, in the code, there is an extra loop entry on termination... a trifle, but it can be removed
It's not that I'm lazy at all, but MT is only on VDSs and you don't experiment on them.
about that :
+- 1 :-) I'll be back from the countryside in a couple of days, I'll check it out...
ps. in addition, in the code extra input to the loop at the end...a trifle, but can be removed
Bravo! After correcting a couple of errors you may have knocked me off the pedestal even without using ArrayCopy. Checkmate. :))
Bravo! After correcting a couple of errors, you've knocked me off the pedestal even without using ArrayCopy. Checkmate. :))
Although not exactly so, because the output array is quite different - already mixed. But it's cool anyway!
Of course, if we are dealing with quotes, this will not work. I'm on the podium again. ))
I've changed the way of calculating the checksum. No longer the simple sum of all elements, but the sum is (element value)/(element number).
And this is what I got: