Welcome to the Monastery | |
PerlMonks |
Re^3: One Zero variants_without_repetitionby grinder (Bishop) |
on Aug 07, 2007 at 13:49 UTC ( [id://631049]=note: print w/replies, xml ) | Need Help?? |
Extrordinaly nice, but whay does it do extra checks - crop some results ? What extra checks? It just hunts through the array, looking for a 0, 1 pair to swap to 1, 0. If it does so, it sorts the tail of the array that it has already walked past so that 0, 1, 1, 0 becomes 1, 0, 0, 1 (instead of 1, 0, 1, 0). The if check is just to avoid sorting empty length sub-arrays. All of your code are wonderful, but unfortunatly i like the second code i posted the most Yeah, but if it produces garbage, what's the point? There's no point in hanging onto code that doesn't work. Your problem interests me as an intellectual challenge, but I cannot summon the motivation to debug your code :) I imagine my code would be very efficient up to several hundred elements. At some point it would become more efficient to examine the tail, count the 0s and 1s, and splice in a newly-constructed tail on the fly, thereby avoiding the sort:
The counting of 0s and 1s is a tad ugly, I admit, but it avoids creating a lexical scope that a classic if/else block would involve. • another intruder with the mooring in the heart of the Perl
In Section
Seekers of Perl Wisdom
|
|