C:\test>215606 No 2-column solutions found There are 1956 3-column solutions C:\test> #### #! perl -slw use strict; my @cols=(0x15); while () { my @c = split' '; $cols[$_] |= ($c[$_]<<($.-1)) for 0..$#c; } my $test = 0; $test |= $_ for @cols; print "There is no solution\n" and exit if $test != 32767; my @found; # look for 2 column solutions... for my $first (0..$#cols) { for my $second (0..$#cols) { next if $first == $second; push @found, [$first,$second] # and print "Columns $first & $second is a solution" if (($cols[$first] | $cols[$second]) == 32767); } } if (@found) { print 'There are ', scalar @found, ' 2-column solutions'; exit; } else { print 'No 2-column solutions found'; } # look for 3 column solutions... for my $first (0..$#cols) { for my $second (0..$#cols) { for my $third (0..$#cols) { next if $first == $second or $first == $third or $second == $third; my $route = $cols[$first] | $cols[$second] | $cols[$third]; push @found, [$first, $second, $third] # and print "Columns $first & $second & $third is a solution" if $route == 32767; } } } if (@found) { print 'There are ', scalar @found, ' 3-column solutions'; exit; } else { print 'No 3-column solutions found\n'; } __DATA__ 1 1 1 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 1 1 0 0 1 0 0 1 0 1 1 1 1 0 0 0 1 1 1 1 1 1 0 1 1 1 0 0 0 0 1 1 1 1 0 1 0 0 1 1 0 0 0 1 1 1 0 0 0 0 0 1 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 0 0 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 1 1 1 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 1 1 0 0 0 1 0 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 0 0 1 1 1 0 1 0 0