diff options
| author | Fourand <4randrofficial@gmail.com> | 2019-10-18 17:16:11 +0500 |
|---|---|---|
| committer | Fourand <4randrofficial@gmail.com> | 2019-10-18 17:16:11 +0500 |
| commit | fab3812047243871a82f3cb070ec9d8fe447ddd0 (patch) | |
| tree | e6da88b96e2167854b55e59dc120e675e82caf71 | |
| parent | ad68e9e4012a134f307bd5d8c59249b8e66d4ab1 (diff) | |
| download | perlweeklychallenge-club-fab3812047243871a82f3cb070ec9d8fe447ddd0.tar.gz perlweeklychallenge-club-fab3812047243871a82f3cb070ec9d8fe447ddd0.tar.bz2 perlweeklychallenge-club-fab3812047243871a82f3cb070ec9d8fe447ddd0.zip | |
update
| -rw-r--r-- | challenge-030/vyacheslav-volgarev/perl5/ch-1.pl | 17 | ||||
| -rw-r--r-- | challenge-030/vyacheslav-volgarev/perl5/ch-2.pl | 7 |
2 files changed, 18 insertions, 6 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..9d3ecc3971 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; |
