diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-10-20 17:41:10 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-20 17:41:10 +0100 |
| commit | 3c890553e1d4da5bf9e0aca029b9f2ca635eb477 (patch) | |
| tree | 1b41e3b6bb7ea2410c86d6b3803a251099a9fad3 | |
| parent | d7d4c1b5175c5d3ef10c17796d74339b3e5119f2 (diff) | |
| parent | 7464f4c04f7767040edc0c870dcb88850aee6193 (diff) | |
| download | perlweeklychallenge-club-3c890553e1d4da5bf9e0aca029b9f2ca635eb477.tar.gz perlweeklychallenge-club-3c890553e1d4da5bf9e0aca029b9f2ca635eb477.tar.bz2 perlweeklychallenge-club-3c890553e1d4da5bf9e0aca029b9f2ca635eb477.zip | |
Merge pull request #812 from Leoltron/ch-30
Solved challenge 30
| -rw-r--r-- | challenge-030/Leoltron/README | 1 | ||||
| -rw-r--r-- | challenge-030/Leoltron/perl5/ch-1.pl | 11 | ||||
| -rw-r--r-- | challenge-030/Leoltron/perl5/ch-2.pl | 22 |
3 files changed, 34 insertions, 0 deletions
diff --git a/challenge-030/Leoltron/README b/challenge-030/Leoltron/README new file mode 100644 index 0000000000..28aeaf66ae --- /dev/null +++ b/challenge-030/Leoltron/README @@ -0,0 +1 @@ +Solution by Leoltron diff --git a/challenge-030/Leoltron/perl5/ch-1.pl b/challenge-030/Leoltron/perl5/ch-1.pl new file mode 100644 index 0000000000..9b23635d2f --- /dev/null +++ b/challenge-030/Leoltron/perl5/ch-1.pl @@ -0,0 +1,11 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use 5.010; + +my $week_day = 2; +for (2019 .. 2099) { + $week_day = ($week_day + ($_ % 4 == 0 ? 2 : 1)) % 7; + say $_ if $week_day == 0; +} 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" + } +} + |
