Hello guys, I am trying to answer a code-chef problem, using perl. To be specific I am trying to answer this problem.
http://www.codechef.com/SEP12/problems/HORSES
I am running to an issue however, around lines 6-10, my program seems to freeze after I enter the following (just an example)
1
2
3 4
It's strange, after the last input taken in, the program just freezes, CPU usage for the process jumps up to 14% and it just sits there, I've tried putting in print statements to check my progress, but it doesn't help. Any ideas?
#!/usr/bin/perl
$i1 = <>;
chomp($i1);
for ($count = 0; $count < $i1; $count++) {
$i2 = <>;
$i3 = <>;
chomp $i2;
chomp $i3;
my @values;
@values = split(/ /, $i3);
my @differences;
my $count1;
my $count2;
my $min;
for ($count1 = 0; $count1 < $i2; $count++) {
for ($count2 = $count1+1; $count2<$i2; $count2++) {
if($count1 = 0 and $count2 = 1)
{
$min =abs($values[$count1]-$values[$count2]);
}
elsif($min> abs($values[$count1]-$values[$count2]))
{
$min = abs($values[$count1]-$values[$count2]);
}
}
}
print $min;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.