aboutsummaryrefslogtreecommitdiff
path: root/challenge-215/james-smith/perl/ch-1.pl
blob: 651cd7bf402a6b9d2aa3ef0b025b63b43548e97a (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
#!/usr/local/bin/perl

use strict;
use warnings;
use feature qw(say);
use Test::More;

my @TESTS = (
 [ ['abc', 'xyz', 'tsu'], 1 ],
 [ ['rat', 'cab', 'dad'], 3 ],
 [ ['baa', 'ill', 'zzy', 'abc' ], 2 ],
 [ ['x', 'y', 'z'],       0 ]
);

sub non_alpha {
  return 0 if length $_[0] <2;
  my($c,$f)=0;
  for(@_) {
    $f='';
    $f gt $_ ? ($c++,last) : ($f=$_) for split //;
  }
  $c
}

sub non_alpha_compact {
  return 0 if length $_[0] <2;
  my($c,$f)=0;
  $f='', map { $f gt $_ ? ($c++,next) : ($f=$_) } split // for @_;
  $c
}


is( non_alpha( @{$_->[0]} ), $_->[1] ) for @TESTS;
done_testing();