Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: dynamic map "quadrant" indexing

by Anonymous Monk
on Aug 14, 2005 at 10:20 UTC ( #483675=note: print w/replies, xml ) Need Help??


in reply to dynamic map "quadrant" indexing

Ok - I did it. Wasn't that hard after all, and now I'll make the code more elegant.
use strict; my $lvl ="@ARGV"; my $out = &idx($lvl); print "@$out\n"; sub idx { my $lvl = shift; my @out = qw(a1 b1 c1 d1); if($lvl == 1) { return \@out; } else { my @tmp = (); for my $o (@out) { push @tmp, "$o$_" for(@{&idx($lvl-1)}); } @out = @tmp; } return \@out; }
Marcel

Replies are listed 'Best First'.
Re^2: dynamic map "quadrant" indexing
by Anonymous Monk on Aug 14, 2005 at 13:42 UTC
    Uhm... well forget it, the code is crap. This one does the right thing:
    sub idx { my $lvl = shift; # ARG1: get level my @out = qw(a1 b1 c1 d1 a2 b2 c2 d2 a3 b3 c3 d3 a4 b4 c4 d4); # init OUT array return \@out if($lvl == 1); # bail out if lvl = 1 my @tmp; for my $o (@out) { push @tmp, map { "$o$_" } @{&idx($lvl-1)}; } return \@tmp; }
    Probably I should not do my coding sunday morning. Marcel

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2020-05-30 13:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (172 votes). Check out past polls.

    Notices?