Horse Racing Duals puzzle discussion


#290

Hi there!
I have problem. In debug when i cerr << a[ i ] << endl at first ‘level’ it’s skips a first number
for example :
input is 3, 5, 8, 9
output is 1
content of a is 5, 8, 9
Language C++ please help


#291

For anyone failing just on “Horses in disorder” validation in C++ while using set: storing Pi stright into set is too slow, better store it disordered into some simpler container and sort it after.


#292

Bonjour, je fais cet exo en Java :

  1. Je stock dans une ArrayList
  2. Je trie par ordre croissant
  3. Les 2 dernières valeurs sont donc les 2 plus puissants chevaux

Malgré cela, le 2eme test ne passe pas, il faut trouver “1” alors que j’ai 55 et 27 en 2 plus grande valeur. Je ne comprend donc pas trop le truc la… Une idée ?

Merci.


#293

Reading the statement of the puzzle another time will help you.


#295

il faut trouver la plus proche différence de puissance entre deux chevaux et non pas la différence des deux chevaux les plus puissants


#296

Hi !
Did it in ruby ! Had to try lots of different sorting algorithms, comb sort, merge sort, quick sort, etc.
Finally, it’s the counting sort that worked out.

Bye ! :slight_smile:


#298

What does validator 6 : Horses in disorder mean and how to solve it.
Can anyone please help.


#299

Please read the instructions properly,
Input: 3, 5, 8, 9 :
3 is the no of inputs the program is going to insert.
5, 8, 9 are the inputs inserted.
I hope this helped :slight_smile:


#300

Bonjour,
je n’arrive pas à trouver une façon plus rapide pour avoir 100% en java… Voici mon code :

        Scanner in = new Scanner(System.in);
    	        int N = in.nextInt();
    	        ArrayList<Integer> puissance  = new ArrayList<Integer>();
    	        int tampon = 0;
    	        int value = 10000000;
    	        for (int i = 0; i < N; i++) {
    	            int pi = in.nextInt();
    	            puissance.add(pi);
    	        }
    	        Collections.sort(puissance);
    	        for (int i = 0; i < puissance.size(); i++) {
    	        	for (int j = i+1; j < puissance.size(); j++) {
    	        			tampon = puissance.get(j) - puissance.get(i);
    	        			if (tampon < value ) {
    		        			value = tampon;
    		        		}
    				}
    			}
    	        System.out.println(value);	        
    	    }

pourriez vous me filer une piste pour avoir 100% svp…
Merci d’avance


#301

Hello VinCe1, try to print in debug when you enter your if condition (for which i and j).


#302

I had trouble with this for quite a while, missing the “shorter distance between first two” problem. That’s when I realized that I was using JavaScript’s sort function without taking into account that these were integers, not strings. Once I fixed that rookie mistake, I passed.


#303

Just a tip: in this kind of problem where the execution speed is decisive, think to comment all your prints apart the last one ! That’s what I didn’t do on the last run :wink:


#304

Hi.

I too am having a validation issue : All tests pass in the IDE, but at validation, the two first (“Simple case” & “Shorter difference on the first 2 horses”) fail. The others pass fine.

Unless each tests have a specific max time, this cannot be a speed issue.

I’m coding in C++.

Is there any way to see the validation sets ?

Thank you.


#305

if you fail the “simple case” validator, it’s not a speed issue, it’s a test between 3 horses. Most likely an issue with your algorithm

If you don’t manage to find the issue, I can send you the validator.


#309

hi everyone!
I got a lil problem in PHP when I store the value of all horse

for ($i = 0; $i < $N; $i++)
{
    fscanf(STDIN, "%d",$Pi);
    if( 0 < $Pi )
    {
    array_push($tab, $Pi);
    }
    error_log(var_export($tab[$i]));

  }

I 'm getting a 0 at the end of $tab, and…
I don’t get it x)
Thanks for the help


#310

Why all that code? Why don’t $tab[] = $Pi ?


#311

I am in the same problem


#312

Maybe someone can give me a clue. I passed all of them, but got points docked for All Horses Tie and Horses in Disorder. I used a C++ Set, so just adding elements to the set inherently puts them in order, and also assures that there are no duplicates, which means that the only way there could be a tie is if a number was compared to itself, and since I compare N to N+1, that can’t happen. Anyone have an idea why it’s being flagged that way? Thanks!


#313

Some things to think about:

  1. Name of the test is ‘All horses tie’.
  2. You’re removing duplicates from the set.

Does that point you in the right direction?


#314

I appreciate the response.
I suppose I must not be understanding something. If we were concerned about which specific horses were the closest, it would make sense to keep all values in the list, even repeating ones, but from a performance perspective, it’s unecessary to compare the same scores multiple times, so using a set that only stores unique numbers makes sense for speed, as we are only concerned with the spread, which would be unique. Also, I don’t understand what is meant by “all horses tie”. If all items in the set are unique, comparing N to anything other than itself, i.e. N+1, could never tie. Sorry, not trying to be thick, just could use a more detailed explaination why it thinks they are a tie, and how not removing duplicates would be more efficient. Thanks for any feedback!