diff options
| author | andrezgz <andrezgz@gmail.com> | 2019-10-16 18:06:38 -0300 |
|---|---|---|
| committer | andrezgz <andrezgz@gmail.com> | 2019-10-16 18:06:38 -0300 |
| commit | 92febb7a11782b9ff765f2d2e4155fefe718635b (patch) | |
| tree | 90682a689ab54e9becd85ab2a3b55cc75621978b | |
| parent | 58dac7fdbda73e9040ee71d8d582291caf66b0d3 (diff) | |
| download | perlweeklychallenge-club-92febb7a11782b9ff765f2d2e4155fefe718635b.tar.gz perlweeklychallenge-club-92febb7a11782b9ff765f2d2e4155fefe718635b.tar.bz2 perlweeklychallenge-club-92febb7a11782b9ff765f2d2e4155fefe718635b.zip | |
challenge-030 andrezgz solution
| -rw-r--r-- | challenge-030/andrezgz/perl5/ch-1.pl | 28 | ||||
| -rw-r--r-- | challenge-030/andrezgz/perl5/ch-1.sh | 5 | ||||
| -rw-r--r-- | challenge-030/andrezgz/perl5/ch-2.pl | 42 |
3 files changed, 75 insertions, 0 deletions
diff --git a/challenge-030/andrezgz/perl5/ch-1.pl b/challenge-030/andrezgz/perl5/ch-1.pl new file mode 100644 index 0000000000..d95b33b4c2 --- /dev/null +++ b/challenge-030/andrezgz/perl5/ch-1.pl @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-030/ +# Task #1 +# Write a script to list dates for Sunday Christmas between 2019 and 2100. +# For example, 25 Dec 2022 is Sunday. + +use strict; +use warnings; + +use DateTime; + +do { print $_.$/ if DateTime->new( year => $_, month => 12, day => 25 )->dow == 7 } for ( 2019 .. 2100 ); + +__END__ + +./ch-1.pl +2022 +2033 +2039 +2044 +2050 +2061 +2067 +2072 +2078 +2089 +2095 diff --git a/challenge-030/andrezgz/perl5/ch-1.sh b/challenge-030/andrezgz/perl5/ch-1.sh new file mode 100644 index 0000000000..1015b530c9 --- /dev/null +++ b/challenge-030/andrezgz/perl5/ch-1.sh @@ -0,0 +1,5 @@ +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-030/ +# Task #1 +# Write a script to list dates for Sunday Christmas between 2019 and 2100. +# For example, 25 Dec 2022 is Sunday. +perl -mDateTime -e 'do { print $_.$/ if DateTime->new( year => $_, month => 12, day => 25 )->dow == 7 } for ( 2019 .. 2100 );' diff --git a/challenge-030/andrezgz/perl5/ch-2.pl b/challenge-030/andrezgz/perl5/ch-2.pl new file mode 100644 index 0000000000..74c492c343 --- /dev/null +++ b/challenge-030/andrezgz/perl5/ch-2.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl + +# https://perlweeklychallenge.org/blog/perl-weekly-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 strict; +use warnings; + +my %groups; + +# duplicates are allowed on the same group +# 0 is ommited in all loops (it's not positive) +for my $first ( 1..10 ) { + for my $second ( 1..10 ) { + my $third = 12 - $first - $second; # the sum is 12 (an even number) so one of them is even + next if $third <= 0; # none of them is negative + my $key = join ' ', # create a unique combination ... + sort { $a <=> $b } # by sorting ... + $first, $second, $third; # the 3 numbers. + print $key.$/ unless $groups{$key}++; # print combination only once. + } +} + + +__END__ + +./ch-2.pl +1 1 10 +1 2 9 +1 3 8 +1 4 7 +1 5 6 +2 2 8 +2 3 7 +2 4 6 +2 5 5 +3 3 6 +3 4 5 +4 4 4 |
