in reply to How do I find if an array has duplicate elements, if so discard it?

Another way.....in constant (long) time.

#! perl -w use Quantum::Superpositions; use strict; local ($,=", ", $\="\n"); my @ary = qw/ 1 2 3 3 4 5 6 6 7 8 9/; my @unique = eigenstates(any(@ary)); print @ary; print @unique; my @dStrings = qw/ alpha alpha bravo charlie delta echo foxtrot charli +e golf golf golf hotel india/; my @uStrings = eigenstates(any(@dStrings)); print @dStrings; print @uStrings; my @chars = eigenstates(any(split //, "the quick brown fox jumps over +the lazy dog")); print sort @chars; __DATA__ C:\test>181519 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9 1, 2, 3, 4, 5, 6, 7, 8, 9 alpha, alpha, bravo, charlie, delta, echo, foxtrot, charlie, golf, gol +f, golf, hotel, india bravo, charlie, india, golf, delta, hotel, alpha, echo, foxtrot , a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w +, x, y, z

Originally posted as a Categorized Answer.

  • Comment on Re: How do I find if an array has duplicate elements, if so discard it?
  • Download Code