Sujet : Re: compare two sorted array, item by item, which one is bigger
De : g-bouras (at) *nospam* otenet.gr (Bouras George)
Groupes : comp.lang.perl.miscDate : 20. May 2024, 11:09:28
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v2f7hc$3u75q$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
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}->{$_}}"
}