# Horse Racing Duals puzzle discussion

#221

Java has a built-in sort function for integers, just use that.

#222

Small challenge: solve it without sorting!

#223

Hi everyone!! Iâm a beginner programmer and curently Iâm stuck in my solution. Itâs writtent in C#. I have this error

Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Solution.Main on line 29

Can anyone can help me why it shows up:(

class Solution
{
static void Main(string[] args)
{
int[] horses = new int[N];
for (int i = 0; i < N; i++)
{
}
Array.Sort(horses);
int minDifference = horses[1] - horses[0];
int currentDifference =0;
for ( int i = 0; i< horses.Length; i++)
{

``````        currentDifference = horses[i+1] - horses[i];
if (minDifference > currentDifference)
{
minDifference = currentDifference;
}
}

// Write an action using Console.WriteLine()
// To debug: Console.Error.WriteLine("Debug messages...");

Console.WriteLine(minDifference);
}
``````

}

#224

Hi

`for ( int i = 0; i< horses.Length; i++)`

`horses[i+1]`

i+1 is outside for the last interation of the loop.

#225

First, when Iâve submitted my code, they say that my algorithm fails with tie horses.
Ok, so Iâve managed to correct it and Iâve entered tie horses in the personalized test and failed.
Then Iâve submitted the algorithm anyway and the tie horses case is success.

#226

Anyway I just want to wish good luck to those who havenât managed to resolve the puzzle yet.
A little advice : Itâs not because simplest solution isnât the best that youâll have to search way too far.

#228

can you tell me how to do it please? iâm a newbie of java and i canât pass this

#229

Hello everyone!
Iâm trying to resolve this puzzle in C++, but I have some problems.
In summary, the output of my code doesnât match with the output of the test case.
I think that the following image summarizes a little bit better the problem:

#230

Use cerr to display debug ouput like âThe difference betweenâŠâ. Use cout only for the expected answer (1)

#231

I resolved
That was the problem
Now, I have to understand the fails in the validators panel !

#232

Hi, I have found a little issue, I hope i am mistaking , when Iâve printed the numbers for input I have found out that the first pw data is missing. This issue is in JAVA. I have manage to pass 91% of validation.
Example of error data

input: 3 5 8 9
output: 5 8 9

code used:
int N = in.nextInt();
for (int i = 0; i < N; i++) {
int pi = in.nextInt();
System.err.println(pi);
}

#233

Hi,
I have realized the bash code thanks for the previous replies which have helped me.
To help you to do it, here are some reminders and some tricks :

The best way to assign a value is ((diff=\$x- \$y)) instead of diff=`expr \$x - \$y`
To get an absolute value, you just have to do it : abs=\${diff#-} instead of any if instruction.

Good luck.

#234

Well, just got a bash achievement, took me a while.

The trick is, that if you extract (i+1)th element from array before (i)th element, it somehow takes extremely more time, so the program needs more time to work than given time limit.

#235

Hello,

Iâm coding using python, and Iâm stuck at 90%, the test number 6 - horses in disorder - does not pass, while the same test in the IDE passes.
I read the hint but I donât know what to perform to optimize the algorithm. When I try to add some test the code become to slow with a lot of horses. My code is after the post

Any help appreciated to help me perform the 100%.

Thanks

``````import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

numbers = []
difference = None

temp = int(raw_input())
if 1 < temp < 100000:
n = temp

for i in xrange(n):
pi = int(raw_input())
if 0 < pi <= 10000000:
numbers.append(pi)

del(n)
# Write an action using print
# To debug: print >> sys.stderr, "Debug messages..."

numbers.sort()

for i,n in enumerate(numbers):
difference_current = abs(numbers[i] - numbers[i-1])
if not difference or (difference_current < difference):
difference = difference_current

print difference``````

#236

Bonjour tout le monde !

Je suis vraiment embĂȘtĂ© avec le test de âChevaux dans le dĂ©sordreâ aussi. Ă§a passe parfaitement cotĂ© IDE mais le validateur me rejette et comme il nâest pas verbeux je ne sais pas si le problĂšme vient du fait que les chevaux ne sont pas triĂ©s ou que le temps de traitement est trop long (sachant que je passe les tests âNombreux chevauxâ).

Jâai testĂ© avec la fonction sort (en JS), tri fusion, tri rapide, tri par insertion Ă  lâinitialisation du tableau, mais rien nây fait je suis toujours bloquĂ© sur ce test cotĂ© validation (il passe toujours cotĂ© IDE)

En vous remerciant !

#237
``````[quote="baptistemm, post:235, topic:38"]
for i,n in enumerate(numbers):
difference_current = abs(numbers[i] - numbers[i-1])
[/quote]
``````

what will be your first i? what do you hold in numbers[first i - 1]?

#238

Bonjour,
JâĂ©choue au deuxiĂšme test de validation (plus petite dirffĂ©rence sur les deux premiers chevaux), et je nâarrive pas Ă  voir pourquoi.
Est-ce quâil y a un moyen de voir les input output de ces tests?
Merci

#239

Est-ce quâil y a un moyen de voir les input output de ces tests?

si tu veux voir du debug, le plus simple comme dĂ©taillĂ© dans le code câest dâĂ©crire sur la stderr.

#240

Hello bvs23bkv33

actually I surrounded the instruction with a condition `if i>0:`, I donât know why it disappeared. However even when I had back the condition the test #6 still fails.

#243

### Dear fellow Coders!

I really need your help with this puzzle. Logically, my code would work perfectly for all test cases, but for some reason it always prnts out a negative value!

My code is here.

By the way, I am using Python 3

I would really appreciate for any ideas on why my code is wrong