/
ch-1.pl
executable file
·47 lines (41 loc) · 881 Bytes
/
ch-1.pl
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
40
41
42
43
44
45
46
47
#!/usr/bin/env perl
#
# You are given a array of positive integers, @ints.
#
# Write a script to find out how many integers have even number of digits.
# Example 1
#
# Input: @ints = (10, 1, 111, 24, 1000)
# Output: 3
#
# There are 3 integers having even digits i.e. 10, 24 and 1000.
#
# Example 2
#
# Input: @ints = (111, 1, 11111)
# Output: 0
#
# Example 3
#
# Input: @ints = (2, 8, 1024, 256)
# Output: 1
#
use strict;
use warnings;
use Test2::V0 -no_srand => 1;
use Data::Dumper;
my $cases = [
[10, 1, 111, 24, 1000],
[111, 1, 11111],
[2, 8, 1024, 256],
];
sub count_even_digits_number
{
my $ints = shift;
return scalar grep { not split('') % 2 } @$ints;
}
is(count_even_digits_number($cases->[0]), 3, 'Example 1');
is(count_even_digits_number($cases->[1]), 0, 'Example 2');
is(count_even_digits_number($cases->[2]), 1, 'Example 3');
done_testing();
exit 0;