Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Quantum::Superpositions prob

by kvale (Monsignor)
on Mar 25, 2004 at 15:03 UTC ( #339755=note: print w/replies, xml ) Need Help??


in reply to Quantum::Superpositions prob

Here is a non-quantum solution:
use warnings; use strict; my @a2 = qw/1 2 2 3 3 3 4 4 4 4 5 6 7/;#list of to_visit my @a1 = qw/1 2 3 4/;#list of visited my %visited; @visited{ @a1 } = 1; @a2 = grep {not exists $visited{ $_ }} @a2; print "list of to visit\n"; print_arrays(\@a2); print "\nlist visited\n"; print_arrays(\@a1); sub print_arrays { my $x = shift; for my $item1 ( @$x ) { print $item1,"\n"; } print "\n"; }
For the quantum solution, just sort the array.

-Mark

Replies are listed 'Best First'.
Re: Re: Quantum::Superpositions prob
by tommycahir (Acolyte) on Mar 25, 2004 at 15:13 UTC
    i want to try to keep them in the original order that they were entered on to the list, thats why i thought that Quantum::superpositions might just remove the duplicate value
      Then go with my solution. The grep function preserves the array order.

      -Mark

        L~R
        tanx for clearing up why the Quantum ::superpositions wasnt working

        kvale
        tanx a million that works a treat
        once again my ass been saved my the wise monks..

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2018-07-16 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (352 votes). Check out past polls.

    Notices?