From f355022ac73bf2ed907ec503333c886da9fce0de Mon Sep 17 00:00:00 2001 From: "Jaldhar H. Vyas" Date: Mon, 24 Jun 2024 23:02:18 -0400 Subject: Challenge 274 by Jaldhar H. Vyas. --- challenge-274/jaldhar-h-vyas/blog.txt | 1 + challenge-274/jaldhar-h-vyas/perl/ch-1.pl | 18 ++++++++++++++ challenge-274/jaldhar-h-vyas/perl/ch-2.pl | 35 ++++++++++++++++++++++++++ challenge-274/jaldhar-h-vyas/raku/ch-1.raku | 18 ++++++++++++++ challenge-274/jaldhar-h-vyas/raku/ch-2.raku | 38 +++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 challenge-274/jaldhar-h-vyas/blog.txt create mode 100755 challenge-274/jaldhar-h-vyas/perl/ch-1.pl create mode 100755 challenge-274/jaldhar-h-vyas/perl/ch-2.pl create mode 100755 challenge-274/jaldhar-h-vyas/raku/ch-1.raku create mode 100755 challenge-274/jaldhar-h-vyas/raku/ch-2.raku 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{]}; +} -- cgit