aboutsummaryrefslogtreecommitdiff
path: root/challenge-279/dave-jacoby/perl/ch-2.pl
blob: 92e8a63a8eb76206d2385ee9ac6d79eaf98450f0 (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
36
37
38
39
#!/usr/bin/env perl

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

my @examples = (

    'perl',
    'book',
    'good morning',
);

for my $input (@examples) {
    my $output = split_string($input) ? 'true' : 'false';

    say <<"END";
        Input:  \$str = "$input"
        Output: $output
END
}

sub split_string ($word) {
    my $l = length $word;
    for my $i ( 1 .. $l ) {
        my $first  = substr $word, 0, $i;
        my $second = substr $word, $i, $l - $i;
        my $ff     = scalar grep { is_vowel($_) } split //, $first;
        my $ss     = scalar grep { is_vowel($_) } split //, $second;
        return 1 if $ff == $ss;
    }
    return 0;
}

sub is_vowel ($letter) {
    my @vowels = qw{a e i o u};
    return 1 if grep { $_ eq $letter } @vowels;
    return 0;
}