Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Efficient selection mechanism?

by choroba (Abbot)
on Jan 14, 2014 at 15:58 UTC ( #1070571=note: print w/ replies, xml ) Need Help??


in reply to Re: Efficient selection mechanism?
in thread Efficient selection mechanism?

Working code:

#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use constant MAX => 20; use constant EMPTY => "\0" x ((MAX / 8) + 1); my @AoA = map [ map int rand 1 + MAX, 1 .. 4 ], 0 .. 1000; my @vectors = (EMPTY) x (MAX + 1); for my $num (0 .. MAX) { for my $pos (0 .. $#AoA) { vec($vectors[$num], $pos, 1) = grep($num == $_, @{ $AoA[$pos] +}) ? 1 : 0; } } print "@$_; " for @AoA; print "\n"; my $subarray = $AoA[0]; say "Selecting: @$subarray."; my $result = EMPTY; for my $num (@$subarray) { $result |= $vectors[$num]; } for my $i (0 .. $#AoA) { say "@{ $AoA[$i] }" unless vec($result, $i, 1); }

Update: Runs under 0.3s for 10_000 quadruples.

لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re^2: Efficient selection mechanism?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (14)
As of 2014-10-31 20:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (223 votes), past polls