in reply to Simple Logic Problem with Perl

I'm not sure if your results and algorithm are in step:
If the index difference of two consecutive sample is 1 take the first colum of the first string PLUS the 2nd column -last one- of the last string.

In your first sample, the index of the first item is 1 and the index of the second item is 2, so the difference is 1 and this rule applies.

We then take the first colum of the first string, which is str1, PLUS the 2nd column -last one- of the last string. Here I'm already stuck: there are three columns, so the second one cannot be the last one. We will assume you mean col2, so the second item in your output should be str4. But in your result it shows str3. Assuming that your results are correct your description of the algorithm must be wrong or I have misunderstood it.

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re^2: Simple Logic Problem with Perl
by Anonymous Monk on Oct 19, 2005 at 12:14 UTC
    Dear Sir,

    I'm terribly sorry if my description was not clear. You are right about my statement above, it was not precise, the first one it should be:
    If the index difference of two consecutive elements of the array is 1 take the 1st colum of all the array i.e  $sample->[0] .. $sample->[-1] PLUS the 2nd column of the last element of the array   $sample->[-1].
    Let me give you the illustration of how I get the result. Basically those enclosed with bar (|) and dash (_) are the one which get selected. Notice also the index difference change.
    my $sample1 |str1 |index = 1 |str3 |index = 2 |str5 |index = 3 |str7 |index = 4 | |_______________ |str9 str10 index = 5 |______________________ my $sample2 |str1 str2 | index = 0 |_________ | |str3 str4 | index = 4' |__________| my $sample3 |str1 | index = 3 | |_________ |str3 str4 index = 4 ____________________ my $sample4 = |str1 | index = 1 |str3 | index = 2 |str5 | index = 3 | |______________ |str7 str8 index = 4 ____________________ |str7 str8 | index = 4 |__________| |str9 str10| index = 6 ___________
    I hope it's clear to you now