in reply to Re^4: Finding all Combinations
in thread Finding all Combinations
Limbic~Region:
The minor bug is that this statement:
never sets the $done flag. I think you meant:$position[0] == @list ? $done = 1 : $next = 1;
And because $done is never set,@position == @list ? $done = 1 : $next = 1;
never executes. It's a truly minor bug though, because you have another bit of code that detects the end condition:return () if $done;
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.)return () if $by > @list;
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Finding all Combinations
by Limbic~Region (Chancellor) on Jun 24, 2006 at 17:30 UTC |
In Section
Seekers of Perl Wisdom