Groups | Search | Server Info | Login | Register


Groups > comp.lang.perl.misc > #24897

Re: compare two sorted array, item by item, which one is bigger

From Bouras George <g-bouras@otenet.gr>
Newsgroups comp.lang.perl.misc
Subject Re: compare two sorted array, item by item, which one is bigger
Date 2024-05-20 13:09 +0300
Organization A noiseless patient Spider
Message-ID <v2f7hc$3u75q$1@dont-email.me> (permalink)
References <slrnutkg19.kdq.hymie@nasalinux.net>

Show all headers | View raw


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}->{$_}}"
}

Back to comp.lang.perl.misc | Previous | NextPrevious in thread | Find similar


Thread

compare two sorted array, item by item, which one is bigger hymie! <hymie@nasalinux.net> - 2024-02-24 19:14 +0000
  Re: compare two sorted array, item by item, which one is bigger Rainer Weikusat <rweikusat@talktalk.net> - 2024-02-26 16:20 +0000
    Re: compare two sorted array, item by item, which one is bigger Rainer Weikusat <rweikusat@talktalk.net> - 2024-02-27 15:37 +0000
    Re: compare two sorted array, item by item, which one is bigger hymie! <hymie@nasalinux.net> - 2024-02-28 15:35 +0000
      Re: compare two sorted array, item by item, which one is bigger Rainer Weikusat <rweikusat@talktalk.net> - 2024-02-28 16:34 +0000
  Re: compare two sorted array, item by item, which one is bigger Bouras George <g-bouras@otenet.gr> - 2024-05-20 13:09 +0300

csiph-web