I've copied what you did and added the iterator and reexpressed the righthand sides in terms of the lengths (the lefts are just the rights from the previous line) and the pattern starts to show up (at least if you click on "download" to view it spread out).

p2+p2len -3-2-1 p2 +0+1+2 p1+p1len-6-5-4-3-2-1 p1 +0+1+2+3+4+5 0 1 2 3 4 5 6 7 8 [a b c d e f 1 2 3] temp I RHS [1]>>>>>>[1] temp = *(p2+0) 0 *(p2 ++0) [d]>>>[d] *(p2+0) = *(p1+3) 0 *(p1 ++(p1len-p2len)) [a]>>>[a] *(p1+3) = *(p1+0) 0 *(p1 ++I) [1]<<<<<<<<<<<<<<<<<<[1] *(p1+0) = temp [2]>>>>[2] temp = *(p2+1) 1 *(p2 ++I) [e]>>>[e] *(p2+1) = *(p1+4) 1 *(p1 ++(p1len-p2len)+I) [b]>>>[b] *(p1+4) = *(p1+1) 1 *(p1 ++I) [2]<<<<<<<<<<<<<<<<[2] *(p1+1) = temp [3]>>[3] temp = *(p2+2) 2 *(p2 ++I) [f]>>>[f] *(p2+2) = *(p1+5) 2 *(p1 ++(p1len-p2len)+I) [c]>>>[c] *(p1+5) = *(p1+2) 2 *(p1 ++I) [3]<<<<<<<<<<<<<<[3] *(p1+2) = temp [1 2 3 a b c d e f]

The pattern doesn't jump out as easily from your second example.

EDIT: I think I got the second one, too. There was a typo that messed me up for a bit, and you solved this one "backwards" so it's easier to reference from the ends of the buffers than the starts, but again there's a pattern:

p2+p2len -4-3-2-1 p2 +0+1+2+3 p1+p1len-9-8-7-6-5-4-3-2-1 L1=la +st element of buffer 1 p1 +0+1+2+3+4+5+6+7+8 L2=la +st element of buffer 2 0 1 2 3 4 5 6 7 8 diff= +p1len-p2len=5 [a b c d e f g h i 1 2 3 4] temp I [4]>>[4] temp = *(p2+3) 0 + *(L2+I) [i]>>>>>[i] *(p2+3) = *(p1+8) 0 + *(L1+I) [e]>>>>>[e] *(p1+8) = *(p1+4) 0 + *(L1-diff+1+I) [a]>>>>>[a] *(p1+4) = *(p1+0) 1 + *(L2+I) [1]<<<<<<<<<<<<<<<[1] *(p1+0) = *(p2+0) 1 + *(L1+I) [f]>>>>>[f] *(p2+0) = *(p1+5) 1 + *(L1-diff+1+I) [b]>>>>>[b] *(p1+5) = *(p1+1) 2 + *(L2+I) [2]<<<<<<<<<<<<<<<[2] *(p1+1) = *(p2+1) 2 + *(L1+I) # I think you had a typo here [g]>>>>>[g] *(p2+2) = *(p1+6) 2 + *(L1-diff+1+I) [c]>>>>>[c] *(p1+6) = *(p1+2) 3 + *(L2+I) [3]<<<<<<<<<<<<<<<[3] *(p1+2) = *(p2+2) 3 + *(L1+I) [h]>>>>>[h] *(p2+2) = *(p1+7) 3 + *(L1-diff+1+I) [d]>>>>>[d] *(p1+7) = *(p1+3) 4 + *(L2+I) [4]<<<<<<<<<<<<<<<<<<<<[4] *(p1+3) = temp [1 2 3 4 a b c d e f g h i]
where the addition has to wrap around as graff describes

In reply to Re^2: [OT] Swapping buffers in place. (partial solution:needs more help!) by bitingduck
in thread [OT] Swapping buffers in place. by BrowserUk

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.