Horse Racing Duals puzzle discussion

My code have an error but I don’t know how. Where can I look for help?

oh so sorry, my bad for posting the code, however, thanks for your help!

I have a feeling you meant “Horse Racing Duels” not “Horse Racing Duals” :wink: But no big deal.

just sort list with some fast sorting and find the lowest d with for loop. I have 100%

Hello!
I got stuck in C. The code runs just fine, except it doesn’t work for “many horses”, after the 30’000 input. Plus it doesn’t run if I don’t declare a random variable which I use for nothing DX. Any recommendations?

Hey!
Did you code a sort function by yourself? If so, it’s probably not performant enough. Take a look to the qsort() function.

Well… yes, and no. First I did sort it myself (cause ofc it’d be more efficient xd) but rewrote it to qsort().
When I used mine it did say smthing like “not optimized enough”. Now it doesn’t give an error, but is faulty :confused:
I still cannot use pictures DX but basically:
‘(i=)83: 9991560
84: 9991560477
85: 9991383

33428: 780257
and the rest is all 780257’
–Result:
‘Found: Nothing’
‘Expected: X’
+ a Segmentation fault on where I store the values in a calloc()-ed int*

/Hope it makes sense :smiley:

Well…
That seems obvious there’s a memory problem. :sweat_smile: But difficult to be more specific without the code.
Can you send it to me via DM (click on my profile picture) ? I’ll take a look tomorrow. If you still need help, of course.

Moi en c++ mais le code répond sur mon ordi mais pas dans le jeu. J’ai utilisé un tableau.

aidez moi s’il vous plait. ça ne répond pas

#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

#include<array>

using namespace std;

const int tmax=100;

using tableau=std::array<int,tmax>;

/**

 * Auto-generated code below aims at helping you parse

 * the standard input according to the problem statement.

 **/

int main()

{

    int a, b, c, d, e, f,h;

       tableau t;

    std::cout << "Saisissez la taille du tableau \n";

    std::cin >> a;

    for (int i = 0; i < a; ++i)

    {

        std::cin >> t[i];

    }

    b = t[0];

    h = t[1];

    e = b - h;

    for (int i = 0; i < a; ++i)

    {

        c = t[i];

        f = t[i + 1];

        d = f - c;

        if (abs(e) > abs(d))

        {

            e = abs(d);

            b = t[i];

            h = t[i + 1];

        }

    

    }

    std::cout << "la valeur de e est "<<e;

    

    cin.ignore();

        // Write an answer using cout. DON'T FORGET THE "<< endl"

        // To debug: cerr << "Debug messages..." << endl;

    return 0;

}

hello @ocisse , please

  • don’t post multiple messages
  • write in english
  • explain the issue you’re having with details (“it does not respond” doesn’t really help us understand what you’re facing)

Hello,

I coded the solution in OCaml, and obviously the last test really doesn’t want to pass. I store everything in an array, I do a quicksort on it, and then I do a single pass on the array checking the adjacent elements keeping the smallest difference at the end, yet it’s not fast enough for the third test. Knowing that I made a quicksort inplace I don’t see how I can make it faster.

hi everybody
I stuck at final test:(
please help me
I code in python3

I m doing this puzzle in C, test1 and test3 passed but i have a trouble in horse desorder, i found the value 2 instead 1.

That is probably because you did not sort the inputs first. The puzzle requires you to find the minimum difference by comparing all the numbers, instead of just consecutive numbers in the order of the inputs.

1 Like

I use quicksort algorithm to sort the input but that give me a not optimised solution for the last test.
thks !!!

Hello! I’ve tried this problem and got the first and second cases correct, but I got a un-optimized error on the third one. My process was to put all of the horse numbers into a table(using lua) and then a make a nested for loop where it gets a value and compares it to the other values in the table and gets the difference of all of them. It stores each of the absolute values of the differences into a current_difference variable and if its lower than the least_difference variable it becomes the new least difference variable, and the least_difference variable is printed out a the end. Is there a way i can optimize this so the 3rd case works?

Yes, the hint is right there on the page:

Is there an issue with the Horses in Disorder test??? I have a simple unique sorted list that compares adjacent values to get the minimum. All tests succeed except for the Disorder test but it makes no sense that if I sort my list, how on earth can the order of the horses make any difference???

realised my own mistake…remember…there can still be horses with the same strength :wink:

2 Likes