aboutsummaryrefslogtreecommitdiff
path: root/challenge-013
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2019-06-20 21:14:50 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2019-06-20 21:14:50 +0100
commit147d231dd4678fb8dd0ff0b1f82e77b7678e9f28 (patch)
tree64f8bb7086146cbd3040c594ca0a3482c058837e /challenge-013
parent6bb65029d0e60f55e5035de465bbfe76fffa3d90 (diff)
downloadperlweeklychallenge-club-147d231dd4678fb8dd0ff0b1f82e77b7678e9f28.tar.gz
perlweeklychallenge-club-147d231dd4678fb8dd0ff0b1f82e77b7678e9f28.tar.bz2
perlweeklychallenge-club-147d231dd4678fb8dd0ff0b1f82e77b7678e9f28.zip
- Added solutions by Lubos Kolouch.
Diffstat (limited to 'challenge-013')
-rw-r--r--challenge-013/lubos-kolouch/perl5/ch-1.pl43
-rw-r--r--challenge-013/lubos-kolouch/perl5/ch-2.pl69
2 files changed, 112 insertions, 0 deletions
diff --git a/challenge-013/lubos-kolouch/perl5/ch-1.pl b/challenge-013/lubos-kolouch/perl5/ch-1.pl
new file mode 100644
index 0000000000..1909b9e14c
--- /dev/null
+++ b/challenge-013/lubos-kolouch/perl5/ch-1.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/perl
+#===============================================================================
+#
+# FILE: 2019w25.pl
+#
+# USAGE: ./2019w25.pl
+#
+# DESCRIPTION: Perl weekly challenge w25
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-013/
+#
+# OPTIONS: ---
+# REQUIREMENTS: ---
+# BUGS: ---
+# NOTES: ---
+# AUTHOR: Lubos Kolouch
+# ORGANIZATION:
+# VERSION: 1.0
+# CREATED: 06/20/2019 09:06:41 PM
+# REVISION: ---
+#===============================================================================
+
+use strict;
+use warnings;
+use Date::Calc qw/check_date Day_of_Week/;
+use 5.020;
+
+my $year = shift // die 'No year passed';
+
+for my $month (1..12) {
+ my $day = 31;
+
+ while ($day) {
+ $day-- until check_date($year, $month, $day);
+
+ if (Day_of_Week($year, $month, $day) == 5) {
+ say $year.'/'.$month.'/'.$day;
+ $day = 1;
+ }
+ $day--;
+ }
+}
+
+
diff --git a/challenge-013/lubos-kolouch/perl5/ch-2.pl b/challenge-013/lubos-kolouch/perl5/ch-2.pl
new file mode 100644
index 0000000000..b1f3465e69
--- /dev/null
+++ b/challenge-013/lubos-kolouch/perl5/ch-2.pl
@@ -0,0 +1,69 @@
+#!/usr/bin/perl
+#===============================================================================
+#
+# FILE: 2019w25_2.pl
+#
+# USAGE: ./2019w25_2.pl
+#
+# DESCRIPTION: Perl weekly challenge w25 - 2
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-013/
+#
+# OPTIONS: ---
+# REQUIREMENTS: ---
+# BUGS: ---
+# NOTES: ---
+# AUTHOR: Lubos Kolouch
+# ORGANIZATION:
+# VERSION: 1.0
+# CREATED: 06/20/2019 09:06:41 PM
+# REVISION: ---
+#===============================================================================
+
+use strict;
+use warnings;
+use 5.020;
+use Data::Dumper;
+
+my $max = shift // die 'No n passed';
+
+my %f_cache;
+my %m_cache;
+
+my @f_result;
+my @m_result;
+
+push @f_result, 1;
+push @m_result, 0;
+
+$f_cache{0} = 1;
+$m_cache{0} = 0;
+
+sub f {
+ my $n = shift;
+
+ my $result = $n - $m_cache{$f_cache{$n-1}};
+
+ push @f_result, $result;
+ $f_cache{$n} = $result;
+}
+
+sub m {
+ my $n = shift;
+
+ my $result = $n - $f_cache{$m_cache{$n-1}};
+
+ push @m_result, $result;
+ $m_cache{$n} = $result;
+}
+
+
+for (1..$max-1) {
+ &f($_);
+ &m($_);
+
+}
+
+say 'F : '. join ",", @f_result;
+say 'M : '. join ",", @m_result;
+
+