BrowserUk:

When I saw your original version, I did basically the same thing (swap strings to make the shorter one last). The only problem is that it flips the order of the alternating characters--I expect the first argument to provide the first character, the second argument to provide the second, etc.

I tried a couple quick hacks on yours (and kcotts) version to make it work the way I wanted, but when I didn't get it quickly, I punted. My quick hacks caused the strings to truncate when I was munging with substr on the left because it seems that I can't count properly today--I got bit several times by fencepost errors. For example, one of my attempts was to use zipC and change the starting value of $n based on which string was shorter, but had no luck--nor patience.

You can see what I mean if you fix line 25:

$ cat 1133959.pl #! perl -slw use strict; . . . snip . . . print zipD( $A, $B ), zipD( $B, $A ); print zipR( $A, $B ), zipR( $B, $A ); . . . snip . . . $ perl 1133959.pl AaBbCcDdEeFGHIJAaBbCcDdEeFGHIJ AaBbCcDdEeFGHIJaAbBcCdDeEFGHIJ Rate rR Rr Dd dD rR 327095/s -- -2% -55% -55% Rr 334881/s 2% -- -54% -54% Dd 720854/s 120% 115% -- -0% dD 721504/s 121% 115% 0% --

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re^4: Merge 2 strings like a zip [benchmark] by roboticus
in thread Merge 2 strings like a zip by tel2

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.