Horse Racing Duals puzzle discussion

there is an error it is looking for 47 but that would mean the 2 best horses for the dule would be “9999999” and “9999952” but there is no “9999952” in the list. I wrote code to test this. here it is::
li = []
w = 0
x = 0
y = 0
z = 0
run = 0

n = int(input())
for i in range(n):
pi = int(input())
li.append(pi)
w = “FALSE”
x = 0
y = 0
for i in li:
if i > x: x = i
y = y + 1

for i in li:
if i == x - 47: W = “TRUE”

z = n - y
print(“x=”,x,“y=”,y,“z=”,z,“IS THERE A 47 POINT SPREAD?”,w, file=sys.stderr)
print(x)

So either it is not explained properly as in they are not looking for “The difference D between the two closest strengths.” but rather they was them split by 2s and then to locate the closest set. This is either a mistake in the fin target witch is “111” by the way or a miss communication in the directions
AS PER PYTHON3

You seem to be assuming that the strongest horse must be one of the racers. Is that requirement mentioned in the problem statement?

just like a lot of other people i succeed in all the tests except horses in disorder.

i just now realised what the problem is. all horses probably have 0 pi (that’s why they are in disorder, all dead)

so your solution must allow for that

finalement plutôt facile avec l’appel à une fonction builtin de python

qu’est ce qui ne va pas avec mon code ?

const N = parseInt(readline());

var chevaux = [];
for (let i = 0; i < N; i++) {
    const pi = parseInt(readline());
    chevaux.push(pi);
};

var diff = chevaux.sort((a,b) => a-b)

                    .map((current, index, array) => current - array[index-1])

                    .slice(1)

                    .sort((a,b => a-b));

                    

console.log(diff[0]);
#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

using namespace std;

/**

 * Auto-generated code below aims at helping you parse

 * the standard input according to the problem statement.

 **/

int main()

{

    int N;

    int dif=0,temp=0;

    cin >> N; cin.ignore();

    int *arr;

    arr=new int[N];

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

        int Pi;

        cin >> Pi; cin.ignore();

        arr[i]=Pi;

    }

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

    {

        cerr << arr[i] << endl;

    }

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

        for (int z=1;z<N;z++)

        {

            cerr << "compare: " << arr[i] << " vs " << arr[z] << endl;

            if(dif != 0){

                int newdif=abs(arr[z] - arr[i]);

                cerr << "newdif: " << newdif << endl;

            if (newdif < dif && newdif!=0){

                dif=newdif;

                cerr << "Correct" << endl;

            }

            }else{

                dif=abs(arr[z]-arr[i]);

            }

            cerr << "dif: " << dif << endl;

        }

    }

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

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

    cout << dif << endl;

}

Any one can found the error?
I has problem at task 3. result is 111 but expect 47

Asking for help. I pass every testcases except the “Horses in disorder”.
Why isn’t my code working on that single test? I got a difference of 2 instead of 1. Any ideas?
Thank you :slight_smile:

const N = parseInt(readline());
let d=10000000;
let p=[]
for (let i = 0; i < N; i++) {
    const pi = parseInt(readline());
    p[i]=pi;
}

p.sort;

for (let j=0; j<N-1; j++) {
    if (Math.abs(p[j+1]-p[j])<d) {
        d=Math.abs(p[j+1]-p[j]);
    }
}

console.log(d);

The sorting of p is not working.

You have to write: p.sort(); then it passes all testcases.

1 Like