There are many ways to approach this problem. One way is:
my %last_seen;
my @arr = (1,2,2,2,3);
for( my $i = 0; $i < @arr; ++$i ) {
if( exists( $last_seen{$arr[$i]} ) &&
$last_seen{$arr[$i]} != $i-1 ) {
die "Not appearing consecutively!";
}
$last_seen{$arr[$i]} = $i;
}
----- Original Message -----
From: "Charles Lu" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, March 07, 2002 4:59 PM
Subject: finding consecutive numbers
>
> Hi
>
> I am trying to think of a quick and simple way to find out if a number
> appears only in consecutive fashion once. In other words, a function that
> will return true if a particular number in a list appears only
consecutively
> once.
>
> For example: Does "2" appear only in consecutive fashion?
>
> (1,2,2,2,3) = True; (1,2,2,3,4,2) = False
>
> (1,2,2,3,4,2,2,) = False <-- consecutive but appears more than once
>
> (1,2,3,4,5,2,2,2,2,2) = False ( see previous reason)
>
> (1,2,3,4) = true <--- appearing only once is okay
>
>
> I would appreciate any help with this problem. thanks alot
>
>
> charles
>
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at
http://explorer.msn.com/intl.asp.
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]