aboutsummaryrefslogtreecommitdiff
path: root/challenge-250/dave-jacoby/perl/ch-2.pl
blob: 1526412d61668dcf6bb4ac16173c1bdf35044289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env perl

use strict;
use warnings;
use experimental qw{ say postderef signatures state };

use List::Util qw{ max };

my @examples = (

    [ "perl", "2", "000", "python", "r4ku" ],
    [ "001",  "1", "000", "0001" ],
);

for my $e (@examples) {
    my $input = join ', ', map {qq{"$_"}} $e->@*;
    my $output = alphanumeric_string_value( $e->@* );

    say <<~"END";
    Input:  \@alphanumstr = ($input)
    Output: $output
    END
}

sub alphanumeric_string_value (@array) {
    my @output;
    for my $s (@array) {
        no warnings;
        my $n = 0;
        if   ( $s =~ /\d/ ) { $n = 0 + $s; }
        else                { $n = length $s; }
        push @output, $n;
    }
    return max @output;
}