Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env perl
- use Modern::Perl '2015';
- use List::Util qw/sum/;
- ###
- my $string = '56 65 74 100 99 68 86 180 90';
- my %sums;
- foreach my $el (split(/\s+/, $string)) {
- my $sum = sum(split(//, $el));
- push @{$sums{$sum}}, $el;
- }
- foreach my $sum (sort {$a<=>$b} keys %sums) {
- print join(' ', sort {$a cmp $b} @{$sums{$sum}});
- print ' ';
- }
- print "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement