Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: counting pairwise incidences

by SimonClinch (Chaplain)
on May 17, 2011 at 14:20 UTC ( #905278=note: print w/ replies, xml ) Need Help??

in reply to counting pairwise incidences

The challenge is only to iterate all the 2-member subsets of the set on a per line basis. For example:

use Data::Dumper; my %pairs = (); while (<>) { chomp; my @found = split; for my $k1 ( @found ); for my $k2 ( @found ) { if ( $k2 gt $k1 ) { # ensuring each pair is counted once o +nly for the line $pairs{ $k1 }{ $k2 }++; } } } } print Dumper \%pairs;
(updated thanks to syntax catch by Wind)

One world, one people

Comment on Re: counting pairwise incidences
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2015-10-04 14:13 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (103 votes), past polls