Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re^2: [OT] Swapping buffers in place.by BrowserUk (Patriarch) |
on Mar 01, 2015 at 20:24 UTC ( [id://1118311]=note: print w/replies, xml ) | Need Help?? |
Okay. I jiggered and poked it (my apologies if you're sensitive to such things), and added a little trace and got this:
Which when run on the 6/3 testcase produces:
6 swaps is a perfect score. and the logic is very clear and very clean. So clean it is beautiful (which always feels right!):
With a 10/7 testcase things are little more muddy:
I'm not sure what to think about that. It sure looks like that, after the first 7(*) have been moved, then you could recurse to move the 3 to the end. Ie. As your algorithm works regardless of long/short ordering, treat it as a 3/7 input. Of course you'd have to 'lie' about the length of the array, which is easy to do in C, but not so in Perl. I'm not sure if that is optimal -- I haven't (tried to) figured a formula, but it won't be grossly over -- but it sure looks like (that phrase again), that after a clean start, the end seems (perhaps, unnecessarily) busy? I'll need to code yours and hdbs algorithms, (and finish my own/graff/bitingduck version, if I can), in C and run them on some big buffers with awkward ratios: eg. 2GB left buffer and 536870909 & 536870923 (primes either side of 2GB/4) which ought to trigger pathological behaviour if it exists. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
In Section
Seekers of Perl Wisdom
|
|