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
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |