graemesandwell
asked on
Lowest number in @numbers
Hi!
There are numbers stored in the @numbers (for example - @numbers={2,4,1,6))
How do I search though the @numbers and look for the lowest avaible number (only whole numbers and no negtives) and assign the lowest number to $lowest.
So in this example, the number 3 would be stored in $lowest.
Thanks in advance!
Graeme Sandwell
There are numbers stored in the @numbers (for example - @numbers={2,4,1,6))
How do I search though the @numbers and look for the lowest avaible number (only whole numbers and no negtives) and assign the lowest number to $lowest.
So in this example, the number 3 would be stored in $lowest.
Thanks in advance!
Graeme Sandwell
ASKER
Hi!
I tested the program (using @numbers=(2,4,1,6} and it just shows me the lowest number which is 1. I need it to print the lowest AVAIABLE number (ie, the lowest number which isn't there).
Thanks!
Graeme
I tested the program (using @numbers=(2,4,1,6} and it just shows me the lowest number which is 1. I need it to print the lowest AVAIABLE number (ie, the lowest number which isn't there).
Thanks!
Graeme
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@numbers{@numbers} = ();
@available = grep{!exists$numbers{$_}}( 1..(sort{$ a<=>$b}@nu mbers)[-1] +1);
$lowest = @available[0];
@available = grep{!exists$numbers{$_}}(
$lowest = @available[0];
@numbers{@numbers} = ();
@available = grep{!exists $numbers{$_}}(1..($#number s+2));
$lowest = $available[0];
@available = grep{!exists $numbers{$_}}(1..($#number
$lowest = $available[0];
@numbers{@numbers} = ();
($lowest, $others) = grep {!exists $numbers{$_}}(1..$#numbers +2);
($lowest, $others) = grep {!exists $numbers{$_}}(1..$#numbers
ASKER
Hi!
It worked. Thanks a lot for everyones help!
Graeme Sandwell
It worked. Thanks a lot for everyones help!
Graeme Sandwell
$numbers[0] = 2;
$numbers[1] = 1;
@sorted_numbers = sort { $a <=> $b } @numbers;
print $sorted_numbers[0]; #this is the lowest