Yeah, it was a space concern. Took things right from the solutions, and code includes other things I was testing (and your suggestion as well).

Details...

#!/usr/bin/perl use strict; use Benchmark qw/cmpthese/; cmpthese( -1, { # orighash => sub { orighash(); }, # twolevel => sub { twolevel(); }, # substring => sub { substring(); }, # blokhead => sub { blokhead(); }, blokchop => sub { blokchop(); }, orig => sub { orig(); }, browserUK => sub { browserUK(); }, ikegami => sub { ikegami(); } } ); sub browserUK { my @strings = qw/111011001010011110100010100001 111010000010010110000010000001 000101011100001000110101110000 000101111101001001111101111110 111011001010111110100010100001 000100010100000000010001010000/; for my $i ( 0 .. $#strings ) { for my $j ( $i + 1 .. $#strings ) { my @counts = ( ( $strings[$i] | $strings[$j] ) =~ tr[0][0], ( ~$strings[$i] & $strings[$j] ) =~ tr[\1][\1], ( $strings[$i] & ~$strings[$j] ) =~ tr[\1][\1], ( $strings[$i] & $strings[$j] ) =~ tr[1][1] ); } } } sub ikegami { my @strings = qw/ 111011001010011110100010100001 111010000010010110000010000001 000101011100001000110101110000 000101111101001001111101111110 111011001010111110100010100001 000100010100000000010001010000 /; s/(?<=.)/\0/g for my @strings1 = @strings; # "abc" => "a\0b\0c\ +0" s/(?=.)/\0/g for my @strings2 = @strings; # "abc" => "\0a\0b\0 +c" for my $i ( 0 .. $#strings ) { for my $j ( $i + 1 .. $#strings ) { my %c; ++$c{$_} for ( $strings1[$i] | $strings2[$j] ) =~ /../g; } } } sub orig { my @strings = qw/111011001010011110100010100001 111010000010010110000010000001 000101011100001000110101110000 000101111101001001111101111110 111011001010111110100010100001 000100010100000000010001010000/; foreach my $string (@strings) { my @items = split //, $string; $string = \@items; } for ( my $i = 0 ; $i < @strings ; $i++ ) { for ( my $j = $i + 1 ; $j < @strings ; $j++ ) { my ( $c00, $c01, $c10, $c11 ) = ( 0, 0, 0, 0 ); for ( my $k = 0 ; $k < @{ $strings[$i] } ; $k++ ) { $c00++ if ${ $strings[$i] }[$k] == 0 && ${ $strings[$j] }[$ +k] == 0; $c01++ if ${ $strings[$i] }[$k] == 0 && ${ $strings[$j] }[$ +k] == 1; $c10++ if ${ $strings[$i] }[$k] == 1 && ${ $strings[$j] }[$ +k] == 0; $c11++ if ${ $strings[$i] }[$k] == 1 && ${ $strings[$j] }[$ +k] == 1; } } } } sub orighash { my @strings = qw/111011001010011110100010100001 111010000010010110000010000001 000101011100001000110101110000 000101111101001001111101111110 111011001010111110100010100001 000100010100000000010001010000/; foreach my $string (@strings) { my @items = split //, $string; $string = \@items; } for ( my $i = 0 ; $i < @strings ; $i++ ) { for ( my $j = $i + 1 ; $j < @strings ; $j++ ) { my %count; ( $count{"00"}, $count{"01"}, $count{"10"}, $count{"11"} ) + = ( 0, 0, 0, 0 ); for ( my $k = 0 ; $k < @{ $strings[$i] } ; $k++ ) { $count{ ${ $strings[$i] }[$k] . ${ $strings[$j] }[$k] +}++; } } } } sub twolevel { my @strings = qw/111011001010011110100010100001 111010000010010110000010000001 000101011100001000110101110000 000101111101001001111101111110 111011001010111110100010100001 000100010100000000010001010000/; foreach my $string (@strings) { my @items = split //, $string; $string = \@items; } for ( my $i = 0 ; $i < @strings ; $i++ ) { for ( my $j = $i + 1 ; $j < @strings ; $j++ ) { my ( $c00, $c01, $c10, $c11 ) = ( 0, 0, 0, 0 ); for ( my $k = 0 ; $k < @{ $strings[$i] } ; $k++ ) { if ( ${ $strings[$i] }[$k] == 0 ) { if ( ${ $strings[$j] }[$k] == 0 ) { $c00++; } else { $c01++; } } else { if ( ${ $strings[$j] }[$k] == 0 ) { $c10++; } else { $c11++; } } } } } } sub substring { my @strings = qw/111011001010011110100010100001 111010000010010110000010000001 000101011100001000110101110000 000101111101001001111101111110 111011001010111110100010100001 000100010100000000010001010000/; for ( my $i = 0 ; $i < @strings ; $i++ ) { for ( my $j = $i + 1 ; $j < @strings ; $j++ ) { my %count; ( $count{"00"}, $count{"01"}, $count{"10"}, $count{"11"} ) + = ( 0, 0, 0, 0 ); for ( my $k = 0 ; $k < length $strings[$i] ; $k++ ) { my $value = substr( $strings[$i], $k, 1 ) . substr( $strings[$j] +, $k, 1 ); $count{$value}++; } } } } sub blokhead { my @strings = qw/111011001010011110100010100001 111010000010010110000010000001 000101011100001000110101110000 000101111101001001111101111110 111011001010111110100010100001 000100010100000000010001010000/; for my $i ( 0 .. $#strings ) { for my $j ( $i + 1 .. $#strings ) { my %count; ( $count{"00"}, $count{"01"}, $count{"10"}, $count{"11"} ) + = ( 0, 0, 0, 0 ); $count{ substr( $strings[$i], $_, 1 ) . substr( $strings[$j], $_, 1 ) }++ for 0 .. length( $strings[$i] ) - 1; # print join( "\t", # $i, $j, $count{"00"}, $count{"01"}, $coun +t{"10"}, # $count{"11"} ), # "\n"; } } } sub blokchop { my @strings = qw/111011001010011110100010100001 111010000010010110000010000001 000101011100001000110101110000 000101111101001001111101111110 111011001010111110100010100001 000100010100000000010001010000/; for my $i ( 0 .. $#strings ) { for my $j ( $i + 1 .. $#strings ) { my %count; ( $count{"00"}, $count{"01"}, $count{"10"}, $count{"11"} ) + = ( 0, 0, 0, 0 ); my ( $str1, $str2 ) = @strings[ $i, $j ]; $count{ chop($str1) . chop($str2) }++ while length($str1) and length($str2); } } }

In reply to Re^4: Speeding permutation counting by albert
in thread Speeding permutation counting by albert

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.