#! perl -slw use strict; use Data::Dump qw[ pp ]; $Data::Dump::WIDTH = 1000; use Time::HiRes qw[ time ]; sub comp { my( $a, $b ) = @_; my $total = unpack( '%32b*', $a | $b ); return ( unpack( '%32b*', $a & $b ) / $total ) - ( unpack( '%32b*', $a ^ $b ) / $total ); } our $N //= 20; my @sets = map pack( 'Q', int rand 2**64 ), 1 .. $N; our $S //= '0101010101010101010101010101010101010101010101010101010101010101'; $S = pack 'b*', $S; our $T //= 0.8; my $start = time; print 'Input: ', unpack 'b*', $S; for ( 0 .. $#sets ) { my $score = comp( $sets[ $_ ], $S ); if( $score > $T ) { printf "%8.6f: %s\n", $score, unpack 'b*', $sets[ $_ ]; } } printf "Comparing 1 against $N sets, took: %.6f seconds\n", time() - $start; __END__ C:\test>996530 -N=15000 -S=1111111111111111111111111111111100000000000000000000000000000000 -T=0.25 Input: 1111111111111111111111111111111100000000000000000000000000000000 0.280000: 1111111111111111111111111111111111111111111111111000000000000001 0.254902: 1111111111111111111111111111111111111111111111111000000000100001 0.254902: 1111111111111111111111111111111111111111111111111000000000001001 0.254902: 1111111111111111111111111111111111111111111111111010000000000001 0.254902: 1111111111111111111111111111111111111111111111111000000000001001 0.254902: 1111111111111111111111111111111111111111111111111000000001000001 Comparing 1 against 15000 sets, took: 0.069085 seconds