aboutsummaryrefslogtreecommitdiff
path: root/challenge-279/e-choroba/perl/ch-1.pl
blob: d11b663b3ae707b3b89af79451e583eef0d4b83c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/perl
use warnings;
use strict;
use experimental qw( signatures );

sub sort_letters($letters, $weights) {
    return join "",
        @$letters[ sort { $weights->[$a] <=> $weights->[$b] } 0 .. $#$weights ]
}

use Test::More tests => 3;

is sort_letters(['R', 'E', 'P', 'L'], [3, 2, 1, 4]), 'PERL', 'Example 1';
is sort_letters(['A', 'U', 'R', 'K'], [2, 4, 1, 3]), 'RAKU', 'Example 2';
is sort_letters(['O', 'H', 'Y', 'N', 'P', 'T'], [5, 4, 2, 6, 1, 3]),
    'PYTHON', 'Example 3';