in reply to Re: Re: Quantum::Superpositions prob
in thread Quantum::Superpositions prob

tommycahir,
Ok, since I have already provided a way to do it using Quantum::Superpositions, I should point out that there certainly are simpler solutions. Since your goal is just to visit all routers, order really should not matter:
my @visited = (1 .. 5); my %unvisited = map { $_ => undef } 1 .. 9; while ( %unvisited ) { delete @{unvisited}{@visited}; for ( keys %unvisited ) { visit( $_, \%unvisited ); # Adds routers to %unvisited push @visited , $_; } }
Now if for some reason order is important to you, you can reverse the array/hash for the stack.
my %visited = map { $_ => undef } (1 .. 4); my @unvisited = (1 .. 9); while ( @unvisited ) { my $router = shift @unvisited; next if exists $visited{$router}; visit ( $router, \@unvisited ); # Adds routers to @unvisited $visited{$router} = undef; }
I hope these solutions are helpful.

Cheers - L~R

Replies are listed 'Best First'.
Re: Re: Re: Re: Quantum::Superpositions prob
by tommycahir (Acolyte) on Mar 25, 2004 at 18:50 UTC
    L~R
    tanx for all the help i think i have it going now. order is important as i want to see what router is connected to what.
    the code i actually used was very similar to what u just given..
    once again your fountain of knowledge amazes me
    thanking you
    tommy