diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-05-02 08:50:31 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-02 08:50:31 +0100 |
| commit | 230e4408e3b2faeb602a2616a1ab2f9ca23e3201 (patch) | |
| tree | e2640b80a9bad07a4bb7f3fa4abf33c21913d0a8 | |
| parent | ee3151aa51b8ad352a33f428c61c6fed0c44b021 (diff) | |
| parent | 927b3585fb743f89f48f458f10be81b394ce2eb0 (diff) | |
| download | perlweeklychallenge-club-230e4408e3b2faeb602a2616a1ab2f9ca23e3201.tar.gz perlweeklychallenge-club-230e4408e3b2faeb602a2616a1ab2f9ca23e3201.tar.bz2 perlweeklychallenge-club-230e4408e3b2faeb602a2616a1ab2f9ca23e3201.zip | |
Merge pull request #3986 from lakpatashi/branch-013
Finished challenge-013 with perl
| -rw-r--r-- | challenge-013/lakpatashi/README | 1 | ||||
| -rwxr-xr-x | challenge-013/lakpatashi/perl/ch-1.pl | 31 | ||||
| -rwxr-xr-x | challenge-013/lakpatashi/perl/ch-2.pl | 23 |
3 files changed, 55 insertions, 0 deletions
diff --git a/challenge-013/lakpatashi/README b/challenge-013/lakpatashi/README new file mode 100644 index 0000000000..bc153bd576 --- /dev/null +++ b/challenge-013/lakpatashi/README @@ -0,0 +1 @@ +Solution by lakpatashi diff --git a/challenge-013/lakpatashi/perl/ch-1.pl b/challenge-013/lakpatashi/perl/ch-1.pl new file mode 100755 index 0000000000..e728f5076e --- /dev/null +++ b/challenge-013/lakpatashi/perl/ch-1.pl @@ -0,0 +1,31 @@ +#!/usr/bin/perl + +use warnings; +use strict; +use Data::Dumper; +use List::Util qw(sum); +use feature qw(switch); + +#part 1 +use Time::Local qw(); + +my $year = 2012; +for my $month (1..12){ + # 5 is friday + printf "%.4d-%.2d-%.2d\n",$year,$month,last_dow_month($year,$month,5); +} + +sub last_dow_month{ + # 0 <= month <= 11 + my ($year, $month, $dow) = @_; + $year += int ($month/12); + $month %= 12; + + # 1 day = 86400 sec + my $time = Time::Local::timegm(0,0,0,1,$month,$year)-86400; + my ($mday,$wday) = (gmtime($time))[3,6]; + return $mday - ($wday - $dow) % 7; +} + + + diff --git a/challenge-013/lakpatashi/perl/ch-2.pl b/challenge-013/lakpatashi/perl/ch-2.pl new file mode 100755 index 0000000000..47d9a19d48 --- /dev/null +++ b/challenge-013/lakpatashi/perl/ch-2.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl + +use warnings; +use strict; +use Data::Dumper; +use List::Util qw(sum); +use feature qw(switch); + +#part 2 +sub F{ + my $n = shift; + return $n<=0? 1: $n - M(F($n-1)); +} + +sub M{ + my $n = shift; + return $n<=0? 0: $n - F(M($n-1)); +} + +print "i\tF(i)\tM(i)\n"; +for my $i (0..10){ + print $i,"\t",F($i),"\t",M($i),"\n"; +} |
