in reply to Re: (OT) A different kind of 'combinatorics'
in thread (OT) A different kind of 'combinatorics'
My first thought was m/(....).*\1/ but that would not detect overlapping repetitions. But I am sure such a regex exists.
I was looking to combine lookaheads with captures to check for dups, but then settled for using index to check for existance, and again, with the offset+1 from the first to check for duplicates.
My brute forcer finds 208 complient patterns in about a minute:
#! perl -slw use strict; use List::Util qw[ shuffle ]; use Algorithm::Combinatorics qw[ combinations permutations]; our $N //= 4; my $Nth2 = 1 << $N; my @pats = map sprintf( "%0${N}b", $_ ), 0 .. $Nth2 -1; my $p; OUTER: for my $i ( 1 << $Nth2 -1 .. 2**( $Nth2 + $N -1 ) - ( 2**$Nth2 +)-1 ) { my $b = sprintf "%0${ \( $Nth2 + $N -1 ) }b", $i; printf "\r$b\t"; for my $pat ( @pats ) { #print( " missing $pat" ), next OUTER unless $p = 1+index $b, $pat; #print( " duplicate $pat" ), next OUTER if 1+index $b, $pat, $p; } for my $i ( 0 .. length( $b ) - $N ) { my $sub = substr $b, $i, $N; for my $j ( 0 .. $#pats ) { printf "%u ", $j if $sub eq $pats[ $j ]; } } print "\tGot one"; }
The second set of numbers is the order of the 4-bit patterns within the 19-bit solutions -- in the vague hope they might give some hint as to a generic algorithm -- now rendered unnecessary as Corion's discovered it is a solved problem.
|
|---|