blob: 9664def925f2f7f6d37c84e4b8e2311e73a6f175 (
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 feature 'say';
use experimental 'signatures';
sub main ($str) {
# Convert the string to lower case
$str = lc $str;
# Start with the first letter
my $current_key = substr( $str, 0, 1 );
# Count the number of times we change keys
my $changes = 0;
foreach my $letter ( split //, $str ) {
if ( $letter ne $current_key ) {
# We need to change key
$current_key = $letter;
$changes++;
}
}
say $changes;
}
main( $ARGV[0] );
|