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";
It is ugly but it works ;)

Hope it helps
UnderMine


In reply to Re: The Matrix by UnderMine
in thread The Matrix by nosbod

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.