aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-019/ruben-westerberg/README12
-rwxr-xr-xchallenge-019/ruben-westerberg/perl5/ch-1.pl22
-rwxr-xr-xchallenge-019/ruben-westerberg/perl5/ch-2.pl40
-rwxr-xr-xchallenge-019/ruben-westerberg/perl6/ch-1.p610
-rwxr-xr-xchallenge-019/ruben-westerberg/perl6/ch-2.p626
5 files changed, 108 insertions, 2 deletions
diff --git a/challenge-019/ruben-westerberg/README b/challenge-019/ruben-westerberg/README
index 60f1fb8f9a..21f3332128 100644
--- a/challenge-019/ruben-westerberg/README
+++ b/challenge-019/ruben-westerberg/README
@@ -2,8 +2,16 @@ Solution by Ruben Westerberg
ch-1.pl and ch-1.p6
===
-Run the program with two arguments to find the longest sub string common to both. alpha numeric characters only.
+Run the program to find months with 5 weekends
ch-2.pl and ch-2.p6
===
-Run the program to demonstrate a priority queue inserting, listing and pulling data until empty
+Example usage
+ perl5 version:
+ ./ch-2.pl -c 20 < input.txt
+
+ perl6 version
+ ./ch-2.p6 --col==20 < inputs.txt
+
+If -c or --col are not specifed a default width of 80 is used
+
diff --git a/challenge-019/ruben-westerberg/perl5/ch-1.pl b/challenge-019/ruben-westerberg/perl5/ch-1.pl
new file mode 100755
index 0000000000..aacec0f8a4
--- /dev/null
+++ b/challenge-019/ruben-westerberg/perl5/ch-1.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Time::Piece;
+use Time::Seconds;
+use List::Util qw<any>;
+use v5.26;
+
+my $s= Time::Piece->strptime("1900","%Y");
+my $e= Time::Piece->strptime("2019","%Y");
+#Find the months with 5 weekends (5 fridays, 5 saturdays and 5 sundays).
+#This is only possible when
+# --month has 31 days
+# --must start with a Friday
+#
+# Search by day as only one day will ever match the start of a month
+
+while ($s < $e) {
+ print $s->strftime("%Y %B"), "\n"
+ if ($s->mday==1) && ($s->day_of_week==5) && any {$s->mon == $_ } (1,3,5,7,8,10,12);
+ $s+=ONE_DAY;
+}
diff --git a/challenge-019/ruben-westerberg/perl5/ch-2.pl b/challenge-019/ruben-westerberg/perl5/ch-2.pl
new file mode 100755
index 0000000000..e555bc72b8
--- /dev/null
+++ b/challenge-019/ruben-westerberg/perl5/ch-2.pl
@@ -0,0 +1,40 @@
+#!/usr/bin/env perl
+#
+use strict;
+use warnings;
+use Getopt::Long;
+use v5.26;
+
+my @lines=<STDIN>;
+
+my @words;
+
+for (@lines) {
+ for ( split " ", $_, ) {
+ push @words, $_, " ";
+ }
+}
+my $col=80;
+GetOptions("col=i" => \$col );
+
+
+while (@words) {
+ state $rem = $col;
+ my $w =$words[0];
+ if (length $w > $col) {
+ print $w,"\n";
+ shift @words;
+ shift @words;
+ next;
+ }
+ if (length $w <= $rem) {
+ print $w;
+ $rem-=length $w;
+ shift @words;
+ }
+ else {
+ print "\n";
+ shift @words if $words[0] eq " ";
+ $rem=$col;
+ }
+}
diff --git a/challenge-019/ruben-westerberg/perl6/ch-1.p6 b/challenge-019/ruben-westerberg/perl6/ch-1.p6
new file mode 100755
index 0000000000..a8f928e2eb
--- /dev/null
+++ b/challenge-019/ruben-westerberg/perl6/ch-1.p6
@@ -0,0 +1,10 @@
+#!/usr/bin/env perl6
+
+my $s=Date.new("1900-01-01");
+my $e=Date.new("2019-01-01");
+my @names=<January Febuary March April May June
+ July August September October November December>;
+for $s..^$e {
+ put .year~" @names[.month-1]"
+ if all(.day-of-month == 1, .day-of-week == 5, .days-in-month == 31);
+}
diff --git a/challenge-019/ruben-westerberg/perl6/ch-2.p6 b/challenge-019/ruben-westerberg/perl6/ch-2.p6
new file mode 100755
index 0000000000..742c736c40
--- /dev/null
+++ b/challenge-019/ruben-westerberg/perl6/ch-2.p6
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl6
+sub MAIN(:$col=80) {
+ my @words=$*IN.lines.split(" ",:v);
+ while @words {
+ state $rem=$col;
+ my $w=@words[0];
+
+ if $w.chars > $col {
+ print $w,"\n";
+ @words.shift;
+ @words.shift;
+ next;
+ }
+ if $w.chars <= $rem {
+ print $w;
+ $rem-=$w.chars;
+ @words.shift;
+ }
+
+ else {
+ print "\n";
+ @words.shift if @words[0] eq " ";
+ $rem=$col;
+ }
+ }
+}