It is ugly but it works ;)use strict; my @matrix=('111000110000010000100', '001111001001011110001', '111110111000011110100', '110001110000010001111', '110001110000100001111', '111111111111001111111', '001110001110111111010', '000111001110111110001', '001001000001010000001', '110111111000011111111', '111001110111110001111', '110110111111111110100', '000111001110001110001', '110111111000101111111', '110110111111001110100'); my (@packed, @size, %hash, @lines); push @packed,pack('B*',$_) for (@matrix); push @size, s/1//g for (@matrix); $hash{$_}++ for (@size); for my $s (sort keys %hash) { while ($hash{$s}) { for my $x (0..$#size) { next if $size[$x]!=$s; my @new_lines=(); $hash{$s}--; my $flag=0; for my $t (@lines) { if (unpack('B*',($t & $packed[$x]))>0) { $flag=1; push @new_lines, ($t & $packed[$x]); } else { push @new_lines, $t; } } push @new_lines, $packed[$x] if (!$flag); @lines = (@new_lines); } } } my $final; for my $row (@packed) { for my $line (@lines) { my $match=unpack('B*',($row & $line)); my $count=1; if ($match>0) { while ($match=~s/^0//g) {$count++}; $final.=$count; last; } } } print "$final\n";
Hope it helps
UnderMine
In reply to Re: The Matrix
by UnderMine
in thread The Matrix
by nosbod
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |