This doesn't answer your question at all but it's still kind of neat. It transforms your example input into the example output by removing repeated lines, vertically and horizontally. It also removes "empty" lines from the edges.
$image = <<IMAGE; 0000000000000000000000 0000000001111100000000 0000000001111100000000 0000000001111100000000 0000000001111100000000 0000011111111111110000 0000011111111111110000 0000011111111111110000 0000011111111111110000 0000000001111100000000 0000000001111100000000 0000000001111100000000 0000000001111100000000 0000000000000000000000 IMAGE $result = transpose( trim( vertical_squish( transpose( trim( vertical_squish( $image ) ) ) ) ) ); $result eq <<EXPECT or die "Failed.\n$result\n"; 010 111 010 EXPECT sub trim { local $_ = shift; s/\A(?:^0+[\r\n]+)+//m; s/(?:^0+[\r\n]+)+\z//m; return $_; } sub vertical_squish { local $_ = shift; s/(^[^\r\n]+[\r\n]+)\1+/$1/gm; return $_; } use Algorithm::Loops 'MapCarU'; sub transpose { local $_ = shift; return join( "", &MapCarU( sub { join( "", @_ ) . "\n" }, map( [ split // ], split( /[\r\n]+/ ) ) ) ); }
⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊
In reply to Re: Pattern Recognition Quest
by diotalevi
in thread Pattern Recognition Quest
by eric256
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |