Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: Quantum::Superpositions prob

by tommycahir (Acolyte)
on Mar 25, 2004 at 15:10 UTC ( #339760=note: print w/replies, xml ) Need Help??


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

how would i go about this, is there much work involved.
What i really am aiming to do is
1.to have an array of routers visited and an array of routers to_visit,
2.then then remove the routers visited from the to_visit array
3.continue to visit each one of these routers in turn finding out what other routers they connected to and adding them to the to_visit array
4.repeat from step 2 till no more left in the to_visit array.

Replies are listed 'Best First'.
Re: Re: Re: Quantum::Superpositions prob
by Limbic~Region (Chancellor) on Mar 25, 2004 at 15:27 UTC
    tommychahir,
    Of course this can be done without Quantum::Superpositions, but since this sounded like fun:
    #! /usr/bin/perl use strict; use warnings; use Quantum::Superpositions; my @array_1 = (1 .. 4); my @array_2 = qw{1 2 2 3 3 3 4 4 4 4 5 6 7}; my @array_3 = eigenstates( any(@array_2) != all(@array_1) ); my @array_4 = Quantum::Superpositions::eigenstates( any(@array_2) != a +ll(@array_1) ); print "Ordered:\n"; print "$_\n" for @array_3; print "Hash:\n"; print "$_\n" for @array_4; { no warnings 'redefine'; *eigenstates = *main::eigenstates; sub eigenstates ($) { my @uniq; my %seen; for ( Quantum::Superpositions::collapse( $_[0] ) ) { push @uniq , $_ if ! $seen{$_}; $seen{$_}++; } return @uniq; } }
    Cheers - L~R
Re: Re: Re: Quantum::Superpositions prob
by Limbic~Region (Chancellor) on Mar 25, 2004 at 18:41 UTC
    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

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://339760]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2018-02-24 22:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (311 votes). Check out past polls.

    Notices?