aboutsummaryrefslogtreecommitdiff
path: root/challenge-030/paulo-custodio/perl/ch-2.pl
blob: 974dca199a07a0a8b7df2b621c12222a0d5c0e3f (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
#!/usr/bin/perl

# Challenge 030
#
# Task #2
# Write a script to print all possible series of 3 positive numbers, where in
# each series at least one of the number is even and sum of the three numbers
# is always 12. For example, 3,4,5.

use Modern::Perl;
use List::Util 'sum';
use List::MoreUtils 'any';

my $sum = shift||12;

for my $i (1..$sum) {
    for my $j ($i+1..$sum) {
        for my $k ($j+1..$sum) {
            if (sum($i, $j, $k) == $sum) {
                if (any {$_%2==0} $i, $j, $k) {
                    say "$i,$j,$k"
                }
            }
        }
    }
}