Horse Racing Duals puzzle discussion

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?

Moderators can’t see official puzzles’ validators nor they can validate or refuse solutions.

Hi ! Does it mean we have to pass the puzzle validators by any means ?

Yes, nearly.

Hi yall, I’m having an issue, I’ve solved this puzzle in 3 different languages: C++, JavaScript and Dart;
The solutions are basically identical between them, but the Dart code times out during the “Many Horses” test. Now I can believe that the C++ code is faster than the Dart code, but JS passing the test while Dart can’t, that seems suspicious…

Please refer to my answer here and see if it helps you.

1 Like

Indeed, this solved my problem, many thanks. However, it is kinda weird that this is necessary. Do you have any idea why?

I have no idea :sweat_smile: