What kind of surreal contest is that?
Anyway, a rather quick solution would be to sort, and then look through the array, checking if the current element is identical to the previous or next. If no, it's unique.
Update: now with code:
# intentionally no warnings used. my @array = qw(1 3 4 55 4 3 4 22 1 3 4 3 2 2 3 34); @array = sort @array; my $prev; for (0..$#array) { my $i = $array[$_]; print "$i\n" if $i != $prev && $i != $array[$_+1]; $prev = $i; }
Second update: Another idea. This one is O(n^2) in theory, but the regex engine being fast makes up for that in practise for low-ish values of n:
my @array = qw(1 3 4 55 4 3 4 22 1 3 4 3 2 2 3 34); my $template = join ' ', @array; study $template; for (@array) { my @matches = ($template =~ /\b$_\b/g); print "$_\n" if 1 == @matches; }
In reply to Re: How to hash without the hash- basic
by moritz
in thread How to hash without the hash- basic
by baxy77bax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |