aboutsummaryrefslogtreecommitdiff
path: root/challenge-030
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-10-20 14:20:07 +0100
committerGitHub <noreply@github.com>2019-10-20 14:20:07 +0100
commit0ea2d548c42c6f6955f2fb6058b28677049d29bc (patch)
tree21a46257685a635608e5ae11110fba7028d53fc4 /challenge-030
parent5706648f8556ee4e673e77df459a23bb1680edf3 (diff)
parenta2f5e92d54597b262e5044843cb0cc041766869f (diff)
downloadperlweeklychallenge-club-0ea2d548c42c6f6955f2fb6058b28677049d29bc.tar.gz
perlweeklychallenge-club-0ea2d548c42c6f6955f2fb6058b28677049d29bc.tar.bz2
perlweeklychallenge-club-0ea2d548c42c6f6955f2fb6058b28677049d29bc.zip
Merge pull request #809 from drclaw1394/master
ruben/drclaw solutions for w30 ch1 and ch2. p5 and p6
Diffstat (limited to 'challenge-030')
-rw-r--r--challenge-030/ruben-westerberg/README12
-rwxr-xr-xchallenge-030/ruben-westerberg/perl5/ch-1.pl11
-rwxr-xr-xchallenge-030/ruben-westerberg/perl5/ch-2.pl19
-rwxr-xr-xchallenge-030/ruben-westerberg/perl6/ch-1.p65
-rwxr-xr-xchallenge-030/ruben-westerberg/perl6/ch-2.p614
5 files changed, 51 insertions, 10 deletions
diff --git a/challenge-030/ruben-westerberg/README b/challenge-030/ruben-westerberg/README
index e6f292a7cb..078e072f1a 100644
--- a/challenge-030/ruben-westerberg/README
+++ b/challenge-030/ruben-westerberg/README
@@ -2,17 +2,9 @@ Solution by Ruben Westerberg
ch-1.pl and ch-1.p6
===
-Run the program with commanline arguments enclosed in single quotes to prevent the shell from performing its own brace expansion. This will to multiple levels of expension and generate all combinations;
- eg
- ./ch-1.pl '{Bob,Tim} say hello to {Mary,Rose}'
-
- this will ouput 4 lines
- Bob say hellow to Mary
- Bob say hellow to Rose
- Tim say hellow to Mary
- Tim say hellow to Rose
+Run program to display all Sunday Xmas dates between years 2019 and 2100
ch-2.pl and ch-2.p6
===
-Run the program to demonstrate calling a C function
+Run program to find all combinations of 3 number sequence which add to 12 and have at least 1 even number
diff --git a/challenge-030/ruben-westerberg/perl5/ch-1.pl b/challenge-030/ruben-westerberg/perl5/ch-1.pl
new file mode 100755
index 0000000000..28e8681055
--- /dev/null
+++ b/challenge-030/ruben-westerberg/perl5/ch-1.pl
@@ -0,0 +1,11 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Time::Piece;
+use Time::Seconds;
+
+print map { $_->strftime("%Y-%m-%d\n") }map {
+ my $t=localtime(0)->add_months(11)->add_years($_-1970)+24*ONE_DAY;
+ $t->_wday == 0? $t: ();
+ }
+(2020..2099);
diff --git a/challenge-030/ruben-westerberg/perl5/ch-2.pl b/challenge-030/ruben-westerberg/perl5/ch-2.pl
new file mode 100755
index 0000000000..c5b6707559
--- /dev/null
+++ b/challenge-030/ruben-westerberg/perl5/ch-2.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use List::Util qw<sum>;
+
+my %s;
+for (2,4,6,8,10) {
+ my $e=$_;
+ my $r=12-$e;
+ for (1..$r-1) {
+ my @val=sort($e,$_,$r-$_);
+ my $key=join ",", @val;
+ $s{$key}=\@val if sum(@val) == 12;
+ }
+}
+
+for (sort keys %s) {
+ print join(",", @{$s{$_}}),"\n";
+}
diff --git a/challenge-030/ruben-westerberg/perl6/ch-1.p6 b/challenge-030/ruben-westerberg/perl6/ch-1.p6
new file mode 100755
index 0000000000..1a6028bd36
--- /dev/null
+++ b/challenge-030/ruben-westerberg/perl6/ch-1.p6
@@ -0,0 +1,5 @@
+#!/usr/bin/env perl6
+(2020..2099).map({
+ my $t=Date.new(year=>$_,month=>12,day=>25);
+ $t.day-of-week==7??$t!!|();
+})>>.put;
diff --git a/challenge-030/ruben-westerberg/perl6/ch-2.p6 b/challenge-030/ruben-westerberg/perl6/ch-2.p6
new file mode 100755
index 0000000000..7611eea9e3
--- /dev/null
+++ b/challenge-030/ruben-westerberg/perl6/ch-2.p6
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl6
+my %s;
+for (2,4,6,8,10) {
+ my $e=$_;
+ my $r=12-$e;
+ for 1..$r-1 {
+ my @val=sort($e,$_,$r-$_);
+ %s{@val.join(",")}=@val if @val.sum ==12;
+ }
+}
+
+for %s.keys.sort {
+ put %s{$_}.join(",");
+}