Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Efficient selection mechanism?

by hdb (Monsignor)
on Jan 14, 2014 at 15:31 UTC ( [id://1070568]=note: print w/replies, xml ) Need Help??


in reply to Efficient selection mechanism?

I'm far too late, my approach is already covered in the posts above. However.

I am translating the integers into a binary representation, pushing it onto each element (just for convenience) and the do a logical bitwise "and" to eliminate the unwanted elements:

use strict; use warnings; use List::Util 'sum'; use Data::Dumper; sub asBinary { sum map { 2**$_ } @_ } my @AoA = ( [ 2, 13, 3, 16 ], [ 10, 1, 11, 6 ], [ 0, 10, 11, 19 ], [ 6, 1, 19, 15 ], [ 17, 6, 18, 12 ], ); push @$_, asBinary( @$_ ) for @AoA; my $mask = asBinary( @{$AoA[0]}[0..3] ); my @good = grep { ~$mask & $_->[4] } @AoA; print Dumper \@good;

Clearly, this has an issue if your integers get larger than 31 or 63 depending on your system.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-20 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found