#! 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"; }