aboutsummaryrefslogtreecommitdiff
path: root/challenge-282/dave-jacoby/perl/ch-2.pl
blob: ee38c2bc28a9e5b90cf933c699ebf8ac51fbe092 (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
#!/usr/bin/env perl

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

my @examples = (    # added a couple test entries

    qw{ pPeERrLl rRr GoO }
);

for my $input (@examples) {
    my $output = changing_keys($input);
    say <<"END";
    Input:  \$str = "$input"
    Output: $output
END
}

sub changing_keys ($input) {
    my $c   = 0;
    my $len = -1 + length $input;
    for my $i ( 1 .. $len ) {
        my $l = fc substr $input, $i - 1, 1;
        my $t = fc substr $input, $i, 1;
        $c++ if $l ne $t;
    }
    return $c;
}