in reply to Re: Unfolding a nDeep structure
in thread Unfolding a nDeep structure
Prints: 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0#!/usr/bin/perl -w use strict; use Data::Diver qw[Dive DiveVal]; use Algorithm::Loops 'NestedLoops'; my @MDA; my $dimension = 3; my $depth = 2; NestedLoops( [ ( [0..$dimension-1] ) x $depth ], sub { DiveVal( \@MDA, @_ ) = 0; } ); $MDA[0][0] += 1; my @AoA; for my $level (0..$dimension-1) { NestedLoops( [ ( [0..$dimension-1] ) x ($depth-1) ], sub { my @indices = @_; my $val = Dive( \@MDA, @indices ); push @{$AoA[$level]}, @$val; } );} for my $row (0..$#AoA) { print "@{$AoA[$row]}\n"; }
Updated: Expected: 1 0 0 0 0 0 0 0 0 ???
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Unfolding a nDeep structure
by blokhead (Monsignor) on Jul 05, 2007 at 23:13 UTC |