aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-06-25 22:34:08 +0100
committerGitHub <noreply@github.com>2024-06-25 22:34:08 +0100
commit29c18ca2cf9a3d0e460cf2a8aedfd6c2b16eb0b0 (patch)
tree20e3f748d106a88806143b65eb5756dfb1034ebf
parent6b2e002330b881bdf16f469c1546e3d61dd76cba (diff)
parentf355022ac73bf2ed907ec503333c886da9fce0de (diff)
downloadperlweeklychallenge-club-29c18ca2cf9a3d0e460cf2a8aedfd6c2b16eb0b0.tar.gz
perlweeklychallenge-club-29c18ca2cf9a3d0e460cf2a8aedfd6c2b16eb0b0.tar.bz2
perlweeklychallenge-club-29c18ca2cf9a3d0e460cf2a8aedfd6c2b16eb0b0.zip
Merge pull request #10327 from jaldhar/challenge-274
Challenge 274 by Jaldhar H. Vyas.
-rw-r--r--challenge-274/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-274/jaldhar-h-vyas/perl/ch-1.pl18
-rwxr-xr-xchallenge-274/jaldhar-h-vyas/perl/ch-2.pl35
-rwxr-xr-xchallenge-274/jaldhar-h-vyas/raku/ch-1.raku18
-rwxr-xr-xchallenge-274/jaldhar-h-vyas/raku/ch-2.raku38
5 files changed, 110 insertions, 0 deletions
diff --git a/challenge-274/jaldhar-h-vyas/blog.txt b/challenge-274/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..17facb53f6
--- /dev/null
+++ b/challenge-274/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2024/06/perl_weekly_challenge_week_274.html
diff --git a/challenge-274/jaldhar-h-vyas/perl/ch-1.pl b/challenge-274/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..a50f916a97
--- /dev/null
+++ b/challenge-274/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+use v5.38;
+
+my $sentance = shift;
+my $repeat = 1;
+
+say
+ join q{ },
+ map {
+ $_ . 'ma' . ('a' x $repeat++);
+ }
+ map {
+ if (/^([^AaEeIiOoUu])(\S+)/) {
+ s/(\S)(\S+)/$2$1/;
+ }
+ $_
+ }
+ split /\s+/, $sentance;
diff --git a/challenge-274/jaldhar-h-vyas/perl/ch-2.pl b/challenge-274/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..2d7ca8bf36
--- /dev/null
+++ b/challenge-274/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+use v5.38;
+
+my %timetable;
+
+for my $route (@ARGV) {
+ my ($freq, $start, $time) = split /\s+/, $route;
+ my $departure = $start;
+ while ($departure < 60) {
+ $timetable{$departure} = $departure + $time;
+ $departure += $freq;
+ }
+}
+
+my @starts = sort { $a <=> $b } keys %timetable;
+my @output;
+
+for my $minute (0 .. 59) {
+ my $next = 0;
+ for my $s (keys @starts) {
+ if ($starts[$s] >= $minute) {
+ $next = $s;
+ last;
+ }
+ }
+ my $later = $next == (scalar @starts - 1)
+ ? $timetable{$starts[0]} + 60
+ : $timetable{$starts[$next + 1]};
+
+ if ($timetable{$starts[$next]} > $later) {
+ push @output, $minute;
+ }
+}
+
+say q{[}, (join q{, }, @output), q{]};
diff --git a/challenge-274/jaldhar-h-vyas/raku/ch-1.raku b/challenge-274/jaldhar-h-vyas/raku/ch-1.raku
new file mode 100755
index 0000000000..a33ec1edc9
--- /dev/null
+++ b/challenge-274/jaldhar-h-vyas/raku/ch-1.raku
@@ -0,0 +1,18 @@
+#!/usr/bin/raku
+
+sub MAIN(
+ $sentance
+) {
+ my $repeat = 1;
+
+ $sentance
+ .words
+ .map({
+ /^ (<-[AaEeIiOoUu]>) (\S+)/ ?? "$1$0" !! $_;
+ })
+ .map({
+ $_ ~ 'ma' ~ ('a' x $repeat++);
+ })
+ .join(q{ })
+ .say;
+} \ No newline at end of file
diff --git a/challenge-274/jaldhar-h-vyas/raku/ch-2.raku b/challenge-274/jaldhar-h-vyas/raku/ch-2.raku
new file mode 100755
index 0000000000..d0dd46607b
--- /dev/null
+++ b/challenge-274/jaldhar-h-vyas/raku/ch-2.raku
@@ -0,0 +1,38 @@
+#!/usr/bin/raku
+
+sub MAIN(
+ *@routes
+) {
+ my %timetable;
+
+ for @routes -> $route {
+ my ($freq, $start, $time) = $route.words;
+ my $departure = $start;
+ while $departure < 60 {
+ %timetable{$departure} = $departure + $time;
+ $departure += $freq;
+ }
+ }
+
+ my @starts = %timetable.keys.sort({ $^a <=> $^b });
+ my @output;
+
+ for 0 .. 59 -> $minute {
+ my $next = 0;
+ for @starts.keys -> $s {
+ if @starts[$s] >= $minute {
+ $next = $s;
+ last;
+ }
+ }
+ my $later = $next == @starts.end
+ ?? %timetable{@starts[0]} + 60
+ !! %timetable{@starts[$next + 1]};
+
+ if %timetable{@starts[$next]} > $later {
+ @output.push($minute);
+ }
+ }
+
+ say q{[}, @output.join(q{, }), q{]};
+}