Hi,
I've got a huge two-dimensional array a[x][y].
Think of x as a coordinate and y as a value at it.
At some ranges of x, there are stretches of zero-values of y, which we can call gaps, such as:
x y
1 2
2 3
3 3
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 3
12 0
13 0
14 4
The task is to 'bridge' those 'gaps' that are 'shorter' than a certain interval (xmax) and have equal y values at the 'boundaries' (y0) - that is, for all x's within this interval, set y=y0.
For example, the gap at x={3;11} should be bridged with y=y0=3 if a user-defined xmax>7.
The gap at x={1;14} should never be bridged, as the y values at its boundaries are different.
It is easy to think of a pretty-much 'language-independent' algorithm for this problem, based on two nested loops.
But my array is really huge, so I am wondering if there is a more efficient Perl-specific solution to it using Perl-specific array functions?
Sorry if it looks a bit confusing and thanks in advance for your help!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.