Horse Racing Duals puzzle discussion

Hi guys,

My horses in disorder test passes in the testing part, but it fails in the submission part, all tests are fine expect this one, any idea why is that so?

thanks for your answer.

Please search and read the relevant discussion above.

2 Likes

I am confused why the ā€œMany Horsesā€ test thinks the answer should be 47. The input is all the numbers from 0 to 99998, thus the difference between 2 horses next to each other would be 1. Am I being really obtuse? The answer should be 1, and 47 makes absolutely no sense to me.

You should look again to those numbers. :wink:

11 Likes

this is the sorted array:

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226

ā€¦

99569, 99570, 99571, 99572, 99573, 99574, 99575, 99576, 99577, 99578, 99579, 99580, 99581, 99582, 99583, 99584, 99585, 99586, 99587, 99588, 99589, 99590, 99591, 99592, 99593, 99594, 99595, 99596, 99597, 99598, 99599, 99600, 99601, 99602, 99603, 99604, 99605, 99606, 99607, 99608, 99609, 99610, 99611, 99612, 99613, 99614, 99615, 99616, 99617, 99618, 99619, 99620, 99621, 99622, 99623, 99624, 99625, 99626, 99627, 99628, 99629, 99630, 99631, 99632, 99633, 99634, 99635, 99636, 99637, 99638, 99639, 99640, 99641, 99642, 99643, 99644, 99645, 99646, 99647, 99648, 99649, 99650, 99651, 99652, 99653, 99654, 99655, 99656, 99657, 99658, 99659, 99660, 99661, 99662, 99663, 99664, 99665, 99666, 99667, 99668, 99669, 99670, 99671, 99672, 99673, 99674, 99675, 99676, 99677, 99678, 99679, 99680, 99681, 99682, 99683, 99684, 99685, 99686, 99687, 99688, 99689, 99690, 99691, 99692, 99693, 99694, 99695, 99696, 99697, 99698, 99699, 99700, 99701, 99702, 99703, 99704, 99705, 99706, 99707, 99708, 99709, 99710, 99711, 99712, 99713, 99714, 99715, 99716, 99717, 99718, 99719, 99720, 99721, 99722, 99723, 99724, 99725, 99726, 99727, 99728, 99729, 99730, 99731, 99732, 99733, 99734, 99735, 99736, 99737, 99738, 99739, 99740, 99741, 99742, 99743, 99744, 99745, 99746, 99747, 99748, 99749, 99750, 99751, 99752, 99753, 99754, 99755, 99756, 99757, 99758, 99759, 99760, 99761, 99762, 99763, 99764, 99765, 99766, 99767, 99768, 99769, 99770, 99771, 99772, 99773, 99774, 99775, 99776, 99777, 99778, 99779, 99780, 99781, 99782, 99783, 99784, 99785, 99786, 99787, 99788, 99789, 99790, 99791, 99792, 99793, 99794, 99795, 99796, 99797, 99798, 99799, 99800, 99801, 99802, 99803, 99804, 99805, 99806, 99807, 99808, 99809, 99810, 99811, 99812, 99813, 99814, 99815, 99816, 99817, 99818, 99819, 99820, 99821, 99822, 99823, 99824, 99825, 99826, 99827, 99828, 99829, 99830, 99831, 99832, 99833, 99834, 99835, 99836, 99837, 99838, 99839, 99840, 99841, 99842, 99843, 99844, 99845, 99846, 99847, 99848, 99849, 99850, 99851, 99852, 99853, 99854, 99855, 99856, 99857, 99858, 99859, 99860, 99861, 99862, 99863, 99864, 99865, 99866, 99867, 99868, 99869, 99870, 99871, 99872, 99873, 99874, 99875, 99876, 99877, 99878, 99879, 99880, 99881, 99882, 99883, 99884, 99885, 99886, 99887, 99888, 99889, 99890, 99891, 99892, 99893, 99894, 99895, 99896, 99897, 99898, 99899, 99900, 99901, 99902, 99903, 99904, 99905, 99906, 99907, 99908, 99909, 99910, 99911, 99912, 99913, 99914, 99915, 99916, 99917, 99918, 99919, 99920, 99921, 99922, 99923, 99924, 99925, 99926, 99927, 99928, 99929, 99930, 99931, 99932, 99933, 99934, 99935, 99936, 99937, 99938, 99939, 99940, 99941, 99942, 99943, 99944, 99945, 99946, 99947, 99948, 99949, 99950, 99951, 99952, 99953, 99954, 99955, 99956, 99957, 99958, 99959, 99960, 99961, 99962, 99963, 99964, 99965, 99966, 99967, 99968, 99969, 99970, 99971, 99972, 99973, 99974, 99975, 99976, 99977, 99978, 99979, 99980, 99981, 99982, 99983, 99984, 99985, 99986, 99987, 99988, 99989, 99990, 99991, 99992, 99993, 99994, 99995, 99996, 99997, 99998]

Your code did not read or handle the input numbers properly.

Please view the raw input by clicking the button above the test cases:

How to solve it in bash can anyone help me?

It was discussed in this thread before. Search and check out the relevant discussion :wink:

I tried to write a c++ solver and it didnā€™t work on the long test, because I was using a custom-made sort function that was slower than the built-in one.
Then I realizedā€¦ they were probably trying to make it so that inefficient sorters would break by putting them in more of a reverse order. So I reversed the order of the array before sorting, and it was fast enough to solve the puzzle.
Maybe add two ā€œmany horseā€ puzzles to prevent this?

I switched to c# and it works!

Canā€™t get my code to pass validators 5th and 6th even though I can pass all the IDE tests.
(passed all the other validators)
5th- all horses tie: I fixed my code to stop the moment difference between any two is 0 and return 0.
6th- Disorder horses: 2nd test in IDE is the same where horses are not in order and my code passed that test but not the validator.
Can anyone help??

Edit: nvm, fixed it. Iā€™d suggest they add more IDE tests in this puzzle.

This is my code so far:

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

#include <stdbool.h>

/**

 * Auto-generated code below aims at helping you parse

 * the standard input according to the problem statement.

 **/

int main()

{

    int N;

    int greatest = 0;

    int answer;

    int twogreat;

    scanf("%d", &N);

    for (int i = 0; i < N; i++) {

        int pi;

        scanf("%d", &pi);

        if(pi > greatest) {

            greatest = pi;

        }

    }

    while(twogreat != greatest) {

        answer = greatest - twogreat;

    }

    answer = abs(answer);

    // Write an answer using printf(). DON'T FORGET THE TRAILING \n

    // To debug: fprintf(stderr, "Debug messages...\n");

    printf("%d\n", answer);

    return 0;

}

Iā€™m a newbie at coding so ave no idea what to do ā€“ my code passes no tests. :slightly_frowning_face:.
Pls help me.

I would suggest you to ignore the coding part for a moment, and focus on the approach first. How would you solve the problem if you are to do so manually? After you are able to come up with the approach, then convert it to code.

Oh thank you! Uā€™re the first person to answer me on any discussion - Iā€™m new here :smiling_face:!

Iā€™m thinking of finding the greatest value and then the second greatest value. (not sure how to work this part into code ā€“ I think this is my main issue) Then I would subtract the second greatest from the greatest, which would give me the answer.

The approach you have described may not necessarily give the correct answer. Letā€™s say the given strengths are 5, 6 and 9. The answer given by your approach is 9 - 6 = 3, while the correct answer is 6 - 5 = 1.

use binary tree

High school coder:) not sure how to do that

Thanks, my dudes and duderinos.

Iā€™ve used Python 3.

  1. Take all your input
  2. Sort the array
  3. Go through a loop with variables for current and min strength
  4. Output the minimum result

Iā€™m doing it in C with a bool array of 10000000 elements, I pass all the 3 tests but 0 validatorsā€¦
Iā€™m a bit lost right now :man_shrugging:

edit: found a bug but only validate the large sets :confused:
edit: mixed two methods to get 100%, a bit dirt :confused:

For javascript on test ā€œShorter difference on the first 2 horsesā€

i considered it as a bug because all run greatly.

It was not a beautiful way but i was mad to get stuck on it, so to pass it, when all other tests worked, i just add on my declarative variable result above the array sort the following start:

let result= Math.abs(array[0] - array[1]);