Horse Racing Duals puzzle discussion

I finally optimized for the final test case, and found that in Java, creating an ArrayList, then sorting it, before moving on works the best. Because then you just have to compare adjacent elements, rather than the whole collection of elements.

1 Like

Simple solution in java (100%): I was surprised it passed the last one actually

[nope}

i dont get it, when i console.log(N) it just give a numberā€¦
and pi give me an error?!?! so where do we get the list of different strength?

Please refer to the default code for how to read the inputs and how to debug (print to error stream).

Hey. ^^

Is the PHP ā€œsortā€ function not accepted in the ā€œHorses in disorderā€ test submission? Because all others tests work correctly except this one (and implementation of others sort methods are too slow for the IDE third test)ā€¦

My PHP code which solves the puzzle uses the ā€œsortā€ function, so I guess the issue is not related to that function. Could there be some other issues with your code?

Thanks for your answer, but I just found the ā€œbugā€ with the expert mode. Well, this one was tricky. x)

Hi! I actually donā€™t understand what the ā€œHorses in disorderā€ mean, we donā€™t have any I/O for that one. I assume from your comment, that there can be horses with equal strength, but I actually ā€œdeleteā€ or replace their position on the array to avoid this issue. But I still canā€™t pass the test. Any advice?

La variable Pi nā€™affiche aucun int dans le terminal, lā€™IDE bug ou bien cā€™est normal ?

you should not ignore horses with the same strength

Think about that statement for a second. If youā€™re supposed to find the horses with the closest strength to each other, and you have two who are equal, and youā€™re intentionally excluding one of them from the searchā€¦ finish that thought.

1 Like

I did 90%
But I canā€™t understand in any way! What do you mean ā€œall horses tieā€?! :thinking:

The previous replies may help you:
https://forum.codingame.com/t/horse-racing-duals-puzzle-discussion/38/313
https://forum.codingame.com/t/horse-racing-duals-puzzle-discussion/38/316

Thanks for the answer!
But, unfortunately, these tips did not make clear the understanding of what they specifically want from me. I tried to add an algorithm that removes duplicates, but the result has not changed.

Does your code output 0 if the horse strengths are 3, 3 and 3?

Yes it is! Only if absolutely all horses are the same.

Upd: Ok, I fixed her! ā€œAll horses tieā€ - done
But but now ā€œHorses in disorderā€ does not pass the test
itā€™s crazy, but itā€™s fun! :triumph:

1 Like

I used a set data type for my first time, c++, and it took care of my code timing out on the big lists. By using a set you can can insert the numbers as you get them, and it inserts the new number in the correct position, thus eliminating processing time of sorting after getting the input.

Hi everyone,
Same as many people, I have 90%, and I donā€™t know why ā€˜Horses in disorderā€™ doesnā€™t pass, I use Collections.sort() on an ArrayList,
thx for your help

Did you read the discussion in this thread? Some of it may be helpful to you.

La mĆŖme pour moi. Je passe les tests ide, mais pas les validateurs. Je pense que mon souci est du aux chevaux ayant une puissance Ć©gale.