Horse Racing Duals puzzle discussion


#265

if you want a container that inserts using operator [] then you should use map instead of list or vector


#267

Hi all,
In Java, I was not able to pass the “Numerous Horses” validation by using a SortedSet (all other tests were green). Instead, I used an ArrayList as suggested by someone.
However, I performed some test on my side and if I add more than 50 numbers, the SortedSet is faster than the ArrayList. With less than 50 numbers, the time are equivalent.
Does someone have an idea why a List is better for this test than the Set?
Thanks


#268

The purpose of a set is to maintain the uniqueness of its elements. In this puzzle duplication of data is allowed (two horses have the same strength). Using set as container can give incorrect results. List is more suitable.

About speed, it is possible for the set to have removed duplication in the data set so that there are less data to process and seems to be faster to produce an answer, an incorrect answer.


#269

It’s still possible to get correct results with the set with following simple addition:

if (!powers_set.add(horse_power)){
println(“0”); // horse with same power already exists
}


#271

Bonjour
j’ai un problème concernant le 2eme test.
Je passe sans souci le 1er et le 3eme test mais le second me renvoi “2” alors que “1” est attendu.
Quelqu’un a-t-il déjà eu ce souci ? (je code en C#)
Merci d’avance. :slight_smile:


#272

For 2nd test correct answer is 1, but your program printed 2 instead. You have to find a bug in your code


#273

Well ! Thanks for this but I already knew it. I wrote it in my previous answer? But I don’t know why only this test doesn’t work.


#274

What kind of help you are seeking for? If its test (not validator) then you can easily print inputs, then debug your code with these specific inputs.


#275

I was looking for someone who had the same problem and solved it. Don’t worry I know how to use debug :slight_smile: but can’t find my error anyway.


#276

I can take a look. Send me the code via personal message


#277

I have problems at validators stage, while basic tests being ok. It’s not speed: I failed “Only 2 horses” too. Is there a way to know reasons and/or see test data for validators?


#279

Using JavaScript, I can’t get past the “Shorter difference on the first 2 horses” test. Every other one works fine and even when I test that case manually, it works fine.


#280

Read the statement carefully again, you might have missed an edge case. If you don’t manage to pass it, I can send you the validator.


#281

Well I don’t think this statement can be misinterpreted, it means the best solution is between the two first horses, I think. But it does work fine when I test this case.


#282

When you solve the test case but fail the same validator, it often means that you made an assumption in your code that isn’t true. Perhaps you optimized for the exact scenario rather than making the solution more general. It can also mean that there is some edge condition that is not being handled properly, like Thibaud said.


#285

There’s a missing detail in the explanation.

If there’s a single horse, the result is that horse’s strenght, rather than 0.

For example:
1
5

The result is 5, not 0.


#286

single horse

the rules specifically said that “1 < N”. that means there are two horses or more.


#287

Problem is my code only passed the last test after I considered this case; hence me posting it here :slight_smile:


#288

I’ve just added following line of code to my solution but it still passes all the tests and all the validators:
if (N == 1) throw new Exception(); That means there is no case with 1 horse (as expected).

I recommend you to check your code one more time because you obviously misunderstood the puzzle rules.


#289

for the one who are very desperate in javascript:
https://www.w3schools.com/jsref/jsref_sort.asp
this sort allows you to check only the ones that are next to each other and it is enough …