Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Variant permutation

by runrig (Abbot)
on Aug 30, 2003 at 17:28 UTC ( #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; }


Comment on Re: Variant permutation
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2014-09-22 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (176 votes), past polls