Re: compare two sorted array, item by item, which one is bigger
Bouras George <[email protected]> Mon, 20 May 2024 13:09:28 +0300
| Newsgroups | comp.lang.perl.misc |
|---|---|
| Organization | A noiseless patient Spider |
| Message-ID | <[email protected]> |
On 24/2/2024 9:14 μ.μ., hymie! wrote:
> I'm sure this is an FAQ if I can just find the correct words to ask my question.
I hope it is not too late for this, or whatever.
My usenet account was deleted , just create a new one , and have a look
at my favorite group.
About the request now.
We must stop writing code no matter the language , everything is about
the right data structures for every specific problem.
So here it is. Thanks, George Bouras
---------------------------
#!/usr/bin/perl
use strict; use warnings; use feature qw/say/;
use Data::Dumper; $Data::Dumper::Purity=1; $Data::Dumper::Terse=1;
$Data::Dumper::Indent=1;
my ($i, %scores, %percent)=(0,,);
$scores{0} = [
[ qw(104 92 92 90 87) ],
[ qw(104 92 92 89 88) ],
[ qw(1 1 1 1 1 ) ],
[ qw(2 2 2 2 2 ) ]
];
$scores{1} = [
[ qw(1 2 3 4 5) ],
[ qw(5 1 2 3 4) ],
[ qw(3 3 3 3 3) ],
[ qw(4 4 4 4 4) ]
];
# Fill the %percent with sums per user for every list
$,=',';
foreach my $player (keys %scores) {
$i=0;
foreach my $list ( @{ $scores{$player} } ) {
push @{$percent{$player}->{ sub {my $s=0; map { $s += $_ } @{$_[0]};
$s}->($list)} } , $i++
}
}
#print Dumper $scores{0};
#print Dumper $scores{1};
#print Dumper \%percent;
# Just print two different list sums of %percent of the person 0
#$"=',';
$i=-1;
foreach (keys %{$percent{0}}) {
last if 2 == ++$i;
say "person:0 , sum:$_, scores_list_offset=@{$percent{0}->{$_}}"
}