blob: 8d4420e62f08df25be21fc16ad077907d642d43e (
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{ fc say postderef signatures state };
use List::Util qw{ sum0 };
my @examples = (
"aabb",
"abab",
"aaa",
"bbb",
);
for my $example (@examples) {
my $output = baftera($example);
say <<"END";
Input: \$str = "$example"
Output: $output
END
}
sub baftera ($str) {
return 'false' unless $str =~ /b/mix;
my $has_b = 0;
for my $i ( 0 .. length $str ) {
my $char = substr $str, $i, 1;
$has_b = 1 if $char eq 'b';
return 'false' if $has_b && $char eq 'a';
}
return 'true';
}
|