aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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";
+}