Horse Racing Duals puzzle discussion

If the tests/validators are consistent with all the descriptions and the constraints in the statement, there is no bug.
If the outputs are correct based on the inputs and the rules in the statement, there is no bug.
If the tests/validators can be run within the CodinGame time constraints instead of everyone having their solution timing out and no way to fix it, there is no bug.
If your code cannot solve any one test/validator out of all of them, there is a bug… in your code only.

1 Like

I also did it in C, but I haven’t stuck it yet with many horses.

Update

Done with many horses

(mod edit: no full code please)

Your unsorted example isn’t really unsorted because the solution in this case (1) can still be derived from two consecutive values (5 and 4). Try something like 5 7 9 4 so that you really have to sort first.

Hi TwoSteps,
could I also get the validator test for “Shorter difference on the first 2 horses”? I’m using BASH and can pass all other tests and validators. I’ve optimized performance (not using read and only a single for loop), I’ve ran my code locally with input that has the solution on the first two entries, and I’ve even initialized my result with the difference between the first two entries. Nothing helps, it’s very strange.
Thanks!

Test is incorrect. Pairs
5
15
17
28
55
requested from me answer ‘1’. But difference between 55 and 28 isn’t 1.

Maybe your code doesn’t read/process the inputs correctly? Also, why would you want the difference between 55 and 28 when you are requested to output the smallest difference?

Using the Array.sort() method is all it needed to pass 100% but I realized this after failing using Quick sort and Insertion sort. Seems like the for loops are really slow.

Can you share the code in C language without using default sorting library (qsort())

No solution codes should be shared on the forum.

1 Like

This puzzle requires a sort algorithm a bit faster than O(n log n) because my traditional quicksort failed but 3-way radix quicksort passed. :grinning:

:1st_place_medal: An achievement will unlock for solving this puzzle in BASH.

:rofl: Fun hint: Python scripts can be execuated in BASH like this:

python -c 'a=100
print(a)
'

I’ve been solving this puzzle in many different languages, but I am having a problem with Dart. In particular, I have been getting a time-out from the many horse case. But it prints out the correct solution to stdout before complaining about the time-out. In fact, even the default code (which just reads the input and outputs the string “answer”) complains of a time-out rather than about having the wrong solution. Can anyone else confirm that they are seeing the same behaviour?

Indeed my original working code now exhibits the same behaviour. You should be able to get rid of the issue by adding the following to the end:

exit(0);
1 Like

Good day,

All validation passed except for “Horses in disorder”.

I am using JS.

This is strange. I’ve even tried using the input suggested above:

[10,5,15,17,3,8,11,28,6,55,7] which passes by returning 1

Does your code output the correct answer for (the first line 5 refers to 5 integers):

5
901
54
990
564
66

The answer should be 12.

Thank you for getting back to me.

Yes, my answer is 12, for that case. I just tested it.

I’ve sent you a PM just now. Would you please take a look? Thanks.

This case of 6 integers may help those unable to pass the “Horses in disorder” validator:

6
210
15
228
29
210
266

The answer should be 0.

3 Likes

For those seeking more challenge here: instead of using the builtin quicksort which unfortunately has the O(n log n) complexity you could implement a count sort or radix sort which will only need O(n) time. But then again, the tests pass without it too so…

Clever :bulb: ! Have the moderators of the site validated the solution, or is it considered cheating?