aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeoltron <leoole5@gmail.com>2019-10-20 21:18:10 +0500
committerLeoltron <leoole5@gmail.com>2019-10-20 21:18:10 +0500
commit7464f4c04f7767040edc0c870dcb88850aee6193 (patch)
tree6eb960d0d944ba09a3120d79944bd939e79379ca
parentbde47a59ad165a93384a7fe0f5c3c7c00fabb626 (diff)
downloadperlweeklychallenge-club-7464f4c04f7767040edc0c870dcb88850aee6193.tar.gz
perlweeklychallenge-club-7464f4c04f7767040edc0c870dcb88850aee6193.tar.bz2
perlweeklychallenge-club-7464f4c04f7767040edc0c870dcb88850aee6193.zip
Solved task 2
-rw-r--r--challenge-030/Leoltron/perl5/ch-2.pl22
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-030/Leoltron/perl5/ch-2.pl b/challenge-030/Leoltron/perl5/ch-2.pl
new file mode 100644
index 0000000000..d497106550
--- /dev/null
+++ b/challenge-030/Leoltron/perl5/ch-2.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use 5.010;
+
+use List::Util qw(min);
+use POSIX qw(ceil);
+
+use constant SUM => 12;
+use constant MIN_FIRST => ceil(SUM / 3);
+use constant MAX_FIRST => SUM - 2;
+
+foreach my $first (MIN_FIRST .. MAX_FIRST) {
+ my $min_second = ceil((SUM -$first) / 2);
+ my $max_second = min($first, SUM - $first - 1);
+ foreach my $second ($min_second .. $max_second) {
+ my $third = SUM - $first - $second;
+ say "$first, $second, $third"
+ }
+}
+