Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Variant permutation

by runrig (Abbot)
on Aug 30, 2003 at 17:28 UTC ( [id://287937]=note: print w/replies, xml ) Need Help??


in reply to Variant permutation

Here is a version of Re (tilly) 1 (perl): What Happened...(perils of porting from c):
#!/usr/bin/perl use strict; use warnings; my @array = ( [1..3],['a'..'b'],['A'..'C'] ); my @prev_value; nested_for( sub { if (@prev_value) { my $diff; for (0..$#prev_value) { if ($prev_value[$_] ne $_[$_]) { $diff = $_; last; } } if (defined $diff) { for (reverse $diff..$#prev_value) { print " ", @prev_value[0..$_]; } print "\n"; } else { print " "; } } print @_; @prev_value = @_[0..$#_-1]; }, reverse @array); sub nested_for { ret_iter(@_)->(); } sub ret_iter { my $fn = shift; my $range = shift; my $sub = sub { $fn->(@_, $_) for @$range }; return @_ ? ret_iter($sub, @_) : $sub; }

Log In?
Username:
Password:

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

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

    No recent polls found