aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-07-29 14:44:58 +0100
committerGitHub <noreply@github.com>2019-07-29 14:44:58 +0100
commit7b2993179395b759945f7a5b4214df2c8f626274 (patch)
treebfafa3b156b5a3e535bac955eb7b27d9a8acb1bb
parentc91c189ef04a8a2eaac6a21fe60bd2e1180881a3 (diff)
parent5b1a2e347f263c66734b2f8a5cd677d6d4709213 (diff)
downloadperlweeklychallenge-club-7b2993179395b759945f7a5b4214df2c8f626274.tar.gz
perlweeklychallenge-club-7b2993179395b759945f7a5b4214df2c8f626274.tar.bz2
perlweeklychallenge-club-7b2993179395b759945f7a5b4214df2c8f626274.zip
Merge pull request #443 from Firedrake/rogerbw-challenge-019
Challenge 19 answers
-rwxr-xr-xchallenge-019/roger-bell-west/perl5/1.pl19
-rwxr-xr-xchallenge-019/roger-bell-west/perl5/2.pl41
2 files changed, 60 insertions, 0 deletions
diff --git a/challenge-019/roger-bell-west/perl5/1.pl b/challenge-019/roger-bell-west/perl5/1.pl
new file mode 100755
index 0000000000..9d5f470d49
--- /dev/null
+++ b/challenge-019/roger-bell-west/perl5/1.pl
@@ -0,0 +1,19 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+# Write a script to display months from the year 1900 to 2019 where
+# you find 5 weekends i.e. 5 Friday, 5 Saturday and 5 Sunday.
+
+use Time::Local;
+use POSIX qw(strftime);
+
+foreach my $y (1900..2019) {
+ foreach my $m (1,3,5,7,8,10,12) {
+ my @d=gmtime(timegm(0,0,0,1,$m-1,$y));
+ if ($d[6]==5) {
+ print strftime('%B %Y',@d),"\n";
+ }
+ }
+}
diff --git a/challenge-019/roger-bell-west/perl5/2.pl b/challenge-019/roger-bell-west/perl5/2.pl
new file mode 100755
index 0000000000..4d1ae70960
--- /dev/null
+++ b/challenge-019/roger-bell-west/perl5/2.pl
@@ -0,0 +1,41 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+# Write a script that can wrap the given paragraph at a specified
+# column using the greedy algorithm.
+
+use Getopt::Std;
+
+my %o=(w => 72);
+getopts('w:',\%o);
+
+my $s=$o{w};
+my @w;
+while (<>) {
+ chomp;
+ if ($_ eq '') {
+ if (@w) {
+ print join(' ',@w),"\n";
+ @w=();
+ $s=$o{w};
+ }
+ print "\n";
+ } else {
+ foreach my $w (split ' ',$_) {
+ my $lw=length($w);
+ if ($lw+1 > $s) {
+ print join(' ',@w),"\n";
+ @w=($w);
+ $s=$o{w}-$lw;
+ } else {
+ push @w,$w;
+ $s-=($lw+1);
+ }
+ }
+ }
+}
+if (@w) {
+ print join(' ',@w),"\n";
+}