Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Welcome to the Monastery
 
PerlMonks  

Re^5: Finding all Combinations

by roboticus (Canon)
on Jun 23, 2006 at 23:07 UTC ( #557339=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Finding all Combinations
in thread Finding all Combinations

Limbic~Region:

The minor bug is that this statement:

$position[0] == @list ? $done = 1 : $next = 1;
never sets the $done flag. I think you meant:

@position == @list ? $done = 1 : $next = 1;
And because $done is never set,

return () if $done;
never executes. It's a truly minor bug though, because you have another bit of code that detects the end condition:

return () if $by > @list;
So I just removed $done entirely. (Actually, looking at my code, when I was rearranging, I removed that last condition. I should've kept it because my code tests for the end condition on every call, where your terminator checks only when it's time to go to the next size of results. I'll update my node to reflect that.)

The other thing I did was remove $end_pos since its value has such a limited lifetime, and add a passel of comments so I wouldn't forget how it works!

Now off to How A Function Becomes Higher Order and yer iterator toot!

--roboticus


Comment on Re^5: Finding all Combinations
Select or Download Code
Re^6: Finding all Combinations
by Limbic~Region (Chancellor) on Jun 24, 2006 at 17:30 UTC
    roboticus,
    That's not in the bug in the sense that it results in incorrect behavior. Minor quibble aside - you are right that it does not belong. It's left over from a previous revisions. The original version I had was much closer to blokhead's code which does not precalulate stop values and ends up spinning cycles doing math every iteration. Next I reversed the array so the index could be used to determine stop value with less math. This was unfortunate because I still had to do some math and reverse the return. Finally, I realized I could precalulate the stop values but didn't do a good job of cleaning up my false starts.

    Thanks for the analysis - glad to have been some help.

    Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://557339]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (13)
As of 2014-04-24 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (565 votes), past polls