Horse Racing Duals puzzle discussion

Comment tu as fait finalement ?
J’ai le même soucis que toi, je fais un sort, il passe bien tous les tests dans l’IDE, par contre contre le testeur me dit que le test “désorde” est faux …

int33h, Thank you. I reduced the array access in my loop by 3 per iteration, and the code passes many horses test now.

EDIT : Mea culpa j’ai obtenu 100% mais je ne comprend toujours pas pourquoi les tests passaient et devenaient faux lors de l’envoi du code.

what is the Horse-racing Duals mean?

I wasted some time with the third test because of sorting in the wrong place. When I corrected that, it worked!

I’ve got 91% score. All tests passed but the “Horses in disorder” validation is failing.

I’m using PHP rsort() function to order the values and get the correct diffs. Almost every user who posted here said they sorted the strengths and took the difference from them.

Isn’t allowed me to use PHP sort-like functions in this puzzle? Is this intended?

http://php.net/manual/en/function.sort.php should be enough

anybody try to resolve it in js?

I was using rsort because I had a reverse logic to compare the numbers.

I fixed that, used sort() instead and got the very same problem: all tests pass green and get stuck only on “Horses in disorder” validation.

I guess there’s some strange behavior on the platform for PHP only, because I see people used sort in their solutions but mine is getting stuck because of the same sort function.

See the screenshot for the validation:

As pointed by user olivethebrave in the chat i had some problems in the loop calculating diffs not with the sort() function itself.

Thanks all for the help. Thanks olivethebrave for your great help!

To get all the point you have to implement it in bash which does not have either…

Thank you sir! I reduced the array access to one in the loop and managed to pass all the tests!

What is it mean “Solve “Horse-racing Duals” problem in Bash and get a 100% score.” I pass 100% and don’t know what condition to get Bash-Reider

You have to get 100% using the language programming named Bash :slight_smile:

I finished mine in bash by adding the index while comparing the elements instead of adding it in the for loop.$((arr[$((i++))]-arr[$i])) is much faster than $((arr[$((i+1))]-arr[$i])). Of course I had to work with negative numbers.

It took me a while to figure it out.

1 Like

The $'s are useless for array indexes: $((arr[i++] - arr[i])) should work fine.

1 Like

Thanks for the tip

I just learnt bash 2 days ago to solve this problem.

Used SortedSet in C# to minimize the number of stored data (no duplicates), and I had a Horse-racing Duals problem… the problem was in the no duplicates part (valid result 0 was imposible). They should have added test for that in editor too.

I didn’t read the whole thread, but want to report that I got 90% in Javascript but 100% in Python3, using the same algorithm.
(used sorted on python and arr.sort() on javascript, not sure if that’s where the problem lies).

JS sort do not sort on Int values by default.
100 < 2

3 Likes