aboutsummaryrefslogtreecommitdiff
path: root/challenge-048
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-02-23 23:52:10 +0000
committerGitHub <noreply@github.com>2020-02-23 23:52:10 +0000
commit9403eb1d8f3e6352128c03c76102115680944661 (patch)
treee6fd0d3ea22b8dc6628796f4112417e4b01a592a /challenge-048
parent89d243142e35f87f8293178516f076e4ece3fe87 (diff)
parent933708b443596d6244aa6b371e7d14f76f986848 (diff)
downloadperlweeklychallenge-club-9403eb1d8f3e6352128c03c76102115680944661.tar.gz
perlweeklychallenge-club-9403eb1d8f3e6352128c03c76102115680944661.tar.bz2
perlweeklychallenge-club-9403eb1d8f3e6352128c03c76102115680944661.zip
Merge pull request #1299 from jaldhar/challenge-048
Challenge 48 by Jaldhar H. Vyas
Diffstat (limited to 'challenge-048')
-rw-r--r--challenge-048/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-048/jaldhar-h-vyas/perl/ch-1.pl25
-rwxr-xr-xchallenge-048/jaldhar-h-vyas/perl/ch-2.pl18
-rwxr-xr-xchallenge-048/jaldhar-h-vyas/raku/ch-1.p624
-rwxr-xr-xchallenge-048/jaldhar-h-vyas/raku/ch-2.p614
5 files changed, 82 insertions, 0 deletions
diff --git a/challenge-048/jaldhar-h-vyas/blog.txt b/challenge-048/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..e3feae6113
--- /dev/null
+++ b/challenge-048/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2020/02/perl_weekly_challenge_week_48.html
diff --git a/challenge-048/jaldhar-h-vyas/perl/ch-1.pl b/challenge-048/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..61bc7f62cb
--- /dev/null
+++ b/challenge-048/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use 5.010;
+
+my @people = (0 .. 49);
+
+my $remaining = scalar @people;
+my $next = 0;
+my $victim = 1;
+
+while ($remaining > 1) {
+ $people[$victim] = undef;
+ $remaining--;
+ do {
+ $next = ($next + 1) % 50;
+ } until defined $people[$next];
+
+ $victim = $next;
+ do {
+ $victim = ($victim + 1) % 50;
+ } until defined $people[$victim];
+}
+
+say +(grep { defined $_; } @people)[0] + 1;
diff --git a/challenge-048/jaldhar-h-vyas/perl/ch-2.pl b/challenge-048/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..eeb57ebd03
--- /dev/null
+++ b/challenge-048/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use 5.010;
+
+my @years =
+ grep {
+ / (?<year> \d\d) $ /gmx;
+ grep { $_ == $+{year}} (10, 20, 30, 40, 50, 60 , 70, 80, 90, 1, 11, 21)
+ } (2000 .. 2999);
+
+for my $year (@years) {
+ (reverse $year) =~ / \A (?<month> \d\d) (?<day> \d\d) \z /gmx;
+
+ if ($+{day} < 23) {
+ say join q{/}, ($+{month}, $+{day}, $year);
+ }
+}
diff --git a/challenge-048/jaldhar-h-vyas/raku/ch-1.p6 b/challenge-048/jaldhar-h-vyas/raku/ch-1.p6
new file mode 100755
index 0000000000..2e638abb4d
--- /dev/null
+++ b/challenge-048/jaldhar-h-vyas/raku/ch-1.p6
@@ -0,0 +1,24 @@
+#!/usr/bin/perl6
+
+multi sub MAIN() {
+ my @people = (0 .. 49);
+
+ my $remaining = @people.elems;
+ my $next = 0;
+ my $victim = 1;
+
+ while $remaining > 1 {
+ @people[$victim] = Nil;
+ $remaining--;
+ repeat {
+ $next = ($next + 1) % 50;
+ } until defined @people[$next];
+
+ $victim = $next;
+ repeat {
+ $victim = ($victim + 1) % 50;
+ } until defined @people[$victim];
+ }
+
+ say @people.grep({ defined $_; })[0] + 1;
+} \ No newline at end of file
diff --git a/challenge-048/jaldhar-h-vyas/raku/ch-2.p6 b/challenge-048/jaldhar-h-vyas/raku/ch-2.p6
new file mode 100755
index 0000000000..ec41c61030
--- /dev/null
+++ b/challenge-048/jaldhar-h-vyas/raku/ch-2.p6
@@ -0,0 +1,14 @@
+#!/usr/bin/perl6
+
+my @years = (2000 .. 2999).grep({
+ / $<year> = (\d\d) $ /;
+ (10, 20, 30, 40, 50, 60 , 70, 80, 90, 1, 11, 21).grep({ $_ == $/<year>})
+});
+
+for @years -> $year {
+ $year.flip ~~ / ^ $<month> = (\d\d) $<day> = (\d\d) $ /;
+
+ if $/<day> < 23 {
+ ($/<month>, $/<day>, $year).join(q{/}).say;
+ }
+}