in reply to Can I get better approach to get solution
Your rules for what you count are a little strange, but this produces the same result.
Update 1: No it doesn't! You caught me out with the duplication of value 43 in @all_data.
Is it any better?
C:\test>p1 use List::Util qw[ sum ];; @selected_data = qw(13 76 90 13 77 100 76 300 13 65 400 74 89 34 65); @all_data = qw(1 5 2 8 12 87 13 76 98 77 89 90 11 65 43 74 43 32 34 67 +);; ++$seen{ $_ } for @selected_data, @all_data;; print sum map{ $_ > 1 ? $_ - 1 : () } values %seen;; 13
Update2: This is better.
@selected_data = qw(13 76 90 13 77 100 76 300 13 65 400 74 89 34 65); @all_data = qw(1 5 2 8 12 87 13 76 98 77 89 90 11 65 43 74 43 32 34 67 +); @seen{ @all_data } = ();; exists $seen{ $_ } and $count++ for @selected_data;; print $count;; 12
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can I get better approach to get solution
by kyle (Abbot) on Feb 13, 2007 at 04:43 UTC | |
by BrowserUk (Patriarch) on Feb 13, 2007 at 04:45 UTC | |
|
Re^2: Can I get better approach to get solution
by Anonymous Monk on Feb 13, 2007 at 05:08 UTC |