aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-10-18 14:15:16 +0100
committerGitHub <noreply@github.com>2019-10-18 14:15:16 +0100
commit2245c92b0afa98b12c102ed02a3d34ceb58f4fc9 (patch)
tree2bb26fc9f85769807ba26f58d00d069f76f17103
parentc937832836261729dbff6e53b22c7a8698a49f28 (diff)
parent6e51b5dfe47733aaa7697b60b9a4470b5045de0d (diff)
downloadperlweeklychallenge-club-2245c92b0afa98b12c102ed02a3d34ceb58f4fc9.tar.gz
perlweeklychallenge-club-2245c92b0afa98b12c102ed02a3d34ceb58f4fc9.tar.bz2
perlweeklychallenge-club-2245c92b0afa98b12c102ed02a3d34ceb58f4fc9.zip
Merge pull request #794 from 4RandR/master
Update
-rw-r--r--challenge-030/vyacheslav-volgarev/perl5/ch-1.pl17
-rw-r--r--challenge-030/vyacheslav-volgarev/perl5/ch-2.pl9
2 files changed, 19 insertions, 7 deletions
diff --git a/challenge-030/vyacheslav-volgarev/perl5/ch-1.pl b/challenge-030/vyacheslav-volgarev/perl5/ch-1.pl
index c677a4a685..f4b08d9167 100644
--- a/challenge-030/vyacheslav-volgarev/perl5/ch-1.pl
+++ b/challenge-030/vyacheslav-volgarev/perl5/ch-1.pl
@@ -1,14 +1,23 @@
+#!/usr/bin/env perl
+
use strict;
use warnings;
use v5.10;
use constant {
- Sunday => 0,
- Wednesday => 3
+ SUNDAY => 0,
+ WEDNESDAY => 3
};
-my $day = Wednesday;
+my $day = WEDNESDAY;
+
+sub is_not_leap_year {
+ my $year = shift;
+ $year % 4 != 0 || ( $year % 100 == 0 && $year % 400 != 0 );
+}
for ( 2020.. 2100 ) {
- say "25 Dec $_ is Sunday" if ( $day += $_ % 4 != 0 || ($_ % 100 == 0 && $_ % 400 != 0) ? 1 : 2 ) % 7 == Sunday;
+ $day += is_not_leap_year( $_ ) ? 1 : 2;
+ $day %= 7;
+ say "25 Dec $_ is Sunday" if $day == SUNDAY;
}
diff --git a/challenge-030/vyacheslav-volgarev/perl5/ch-2.pl b/challenge-030/vyacheslav-volgarev/perl5/ch-2.pl
index 978846d43a..5fc17c7efa 100644
--- a/challenge-030/vyacheslav-volgarev/perl5/ch-2.pl
+++ b/challenge-030/vyacheslav-volgarev/perl5/ch-2.pl
@@ -1,6 +1,9 @@
+#!/usr/bin/env perl
+
use strict;
use warnings;
use v5.10;
+use List::Util qw( uniqstr );
my @numbers;
@@ -8,9 +11,9 @@ for my $first ( 1..10 ) {
for my $second (1..10) {
my $third = 12 - $first - $second;
- push @numbers, join ", ", sort ( $first, $second, $third ) if $third > 0;
+ push @numbers, join ", ", sort { $a <=> $b } ( $first, $second, $third ) if $third > 0;
}
}
-my %uniq;
+
$, = ";\n";
-say sort grep !$uniq{$_}++, @numbers;
+say uniqstr @numbers;