in reply to Perl Weekly Challenge 206 with List::Util

For the second task, it looks to me like you want to choose ...

the two largest numbers as the first pair and the next two largest as the second pair, and add the smaller of each: my @descending = sort { $b <=> $a } @input; say $descending[1] + $descending[3];

Edited: I misread the task.

Replies are listed 'Best First'.
Re^2: Perl Weekly Challenge 206 with List::Util
by LanX (Saint) on Mar 17, 2023 at 18:06 UTC
    Are you saying descending is better than ascending? 🤷🏻‍♂️

    The task guaranties even numbered lists, and it doesn't matter in which direction I sum up.

    Tho I could have avoided sum map ... pairs with a for loop and a

    • $sum += $_ if ++$i % 2

    inside, hence avoiding the dependency on List::Util

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery

      My apologies, I misread the question: somehow I got it into my head that we wanted the sum of at most two numbers.