I want to make the upper half a symmetrical one to the lower.
Ah! Thought it was too easy. That'll take 2 lines :)
#! perl -slw
use strict;
use Data::Dump qw[ pp ];
sub fillLTM {
my @lt;
my $n = 1;
push @lt, [ splice @_, 0, $n++ ] while @_;
return @lt;
}
## read raw data
while( my $rawData = <DATA> ) {
## Populate LT matrix
my @lt = fillLTM( split ' ', $rawData );
pp \@lt;;
for my $y ( 0 .. $#lt -1 ) {
push @{ $lt[$y] }, $lt[$_][$y] for $y+1 .. $#{ $lt[-1] };
}
pp \@lt;;
}
__DATA__
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Produces:
C:\test>junk
[
[1],
[2, 3],
[4, 5, 6],
[7, 8, 9, 10]
]
[
[1, 2, 4, 7],
[2, 3, 5, 8],
[4, 5, 6, 9],
[7, 8, 9, 10]
]
[
[ 1],
[ 2, 3],
[ 4, 5, 6],
[ 7, 8, 9, 10],
[11, 12, 13, 14, 15]
]
[
[ 1, 2, 4, 7, 11],
[ 2, 3, 5, 8, 12],
[ 4, 5, 6, 9, 13],
[ 7, 8, 9, 10, 14],
[11, 12, 13, 14, 15]
]
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.