Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Pugs Powerset With Progressive Ordering

by Limbic~Region (Chancellor)
on Apr 26, 2005 at 01:12 UTC ( [id://451398]=perlmeditation: print w/replies, xml ) Need Help??

All,
I also have successfully written my first perl 6 code! It was a pretty straight forward port of Generating powerset with progressive ordering. The only thing Pugs didn't have that I wanted was @array.end which I am in the process of writing a test for. You see autrijus and the Pugs team has this deal where they will trade working code for a proper test.
use v6; sub iter_powerset ( *@factor ) returns Ref { my @subset = (undef) xx @factor.end; my ($pos, $mode) = (-1, 1); my $return = sub { list @factor[ grep { defined $_ } @subset ] }; my %dispatch = ( 1 => sub { ++$pos; @subset[ $pos ] = $pos; ++$mode if $pos == @factor.end; $return(); }, 2 => sub { @subset[ $pos - 1 ] = undef; ++$mode; $return(); }, 3 => sub { @subset[ $pos-- ] = undef; while ( $pos >= 0 ) { last if defined @subset[ $pos ]; --$pos; } @subset[ $pos++ ] = undef; return () if ! $pos; @subset[ $pos ] = $pos; $mode = 1; $return(); }, ); return sub { %dispatch{ $mode }() }; } my $next = iter_powerset( 1..5 ); my @combo; while ( @combo = $next() ) { @combo.say; }
Incidently, the @array.end feature was waiting for me as soon as I checked in the test.

Cheers - L~R

Replies are listed 'Best First'.
Re: Pugs Powerset With Progressive Ordering
by audreyt (Hermit) on Apr 26, 2005 at 18:03 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://451398]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-18 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found