Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Pair of items

by swkronenfeld (Hermit)
on Jul 29, 2003 at 20:10 UTC ( [id://278962]=note: print w/replies, xml ) Need Help??


in reply to Pair of items

artist,

A better problem description is necessary. Do you just want to find any pair of items with no similar numbers? Do you want to continue to find them after the first one? If so, can you use the same item in multiple matches? Assuming the answers to the questions are yes, yes, and no, here's a basic skeleton for your code, using dragonchild's above subroutine

for(my $i=0; $i<@array; $i++) { next if(!$array[$i]); for(my$j=0; $j<@array; $j++) { next if($i == $j); next if(!$array[$j]); if(is_ok($array[$i], $array[$j]) { print "Found a match, $array[$i], $array[$j]"; $array[$i] = $array[$j] = ""; } } }
edit: originally had next if(!$i) and next if(!$j) which dragonchild pointed out to me. Corrected above (next if(!$array[$i]))

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://278962]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-03-29 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found