in reply to Finding the intersect of two ranges

Hashes to the rescue!
sub intersection_length { my($h1, $h2) = ( { map { $_ => 1 } @{$_[0]} }, { map { $_ => 1 } @{$_[1]} } ); return scalar grep exists $h2->{$_}, keys %$h1; } print intersection_length([ 1 .. 5 ], [ 2 .. 6 ]), $/; __output__ 4
Not optimal, but quite succinct :)
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Finding the intersect of two ranges
by caedes (Pilgrim) on Feb 04, 2003 at 02:14 UTC
    Notice that I said Real numbers, not neccesarily integers!! =)

    -caedes