diff options
| author | E7-87-83 <fungcheokyin@gmail.com> | 2024-06-23 20:51:12 +0800 |
|---|---|---|
| committer | E7-87-83 <fungcheokyin@gmail.com> | 2024-06-23 20:51:12 +0800 |
| commit | 63dc85670a33c9d081fa9764fff45df4e0fbaeed (patch) | |
| tree | 2b74a7c6793ee0ff739fb5f193d9f54a1e1be82a | |
| parent | 22b6b07c3a99ccee0a10870b3a22d7b14c1c3f21 (diff) | |
| download | perlweeklychallenge-club-63dc85670a33c9d081fa9764fff45df4e0fbaeed.tar.gz perlweeklychallenge-club-63dc85670a33c9d081fa9764fff45df4e0fbaeed.tar.bz2 perlweeklychallenge-club-63dc85670a33c9d081fa9764fff45df4e0fbaeed.zip | |
Week 274
| -rw-r--r-- | challenge-274/cheok-yin-fung/perl/ch-1.pl | 34 | ||||
| -rw-r--r-- | challenge-274/cheok-yin-fung/perl/ch-2.pl | 33 |
2 files changed, 67 insertions, 0 deletions
diff --git a/challenge-274/cheok-yin-fung/perl/ch-1.pl b/challenge-274/cheok-yin-fung/perl/ch-1.pl new file mode 100644 index 0000000000..d63df6ed7c --- /dev/null +++ b/challenge-274/cheok-yin-fung/perl/ch-1.pl @@ -0,0 +1,34 @@ +# The Weekly Challenge 274 +# Task 1 Goat Latin +use v5.30.0; +use warnings; + +sub gl { + my $sent = $_[0]; + my @words = split " ", $sent; + for my $i (0..$#words) { + $words[$i] = trf($words[$i]) . "a" x ($i+1); + } + return join " ", @words; + +} + +sub trf { + my $word = $_[0]; + if ($word =~ /^[aeiou]/i) { + $word .= "ma"; + } + else { + $word = substr($word,1).substr($word,0,1)."ma"; + } + return $word; +} + +use Test::More tests=>3; +ok gl("I love Perl") eq "Imaa ovelmaaa erlPmaaaa"; +ok gl("Perl and Raku are friends") + eq + "erlPmaa andmaaa akuRmaaaa aremaaaaa riendsfmaaaaaa"; +ok gl("The Weekly Challenge") + eq + "heTmaa eeklyWmaaa hallengeCmaaaa"; diff --git a/challenge-274/cheok-yin-fung/perl/ch-2.pl b/challenge-274/cheok-yin-fung/perl/ch-2.pl new file mode 100644 index 0000000000..caee0378b9 --- /dev/null +++ b/challenge-274/cheok-yin-fung/perl/ch-2.pl @@ -0,0 +1,33 @@ +# The Weekly Challenge 274 +# Task 2 Bus Route +# Example 1 Calculation only, too lazy +use v5.30.0; +use warnings; +use List::Util qw/first/; +my $r1 = [12, 11, 41]; +my $r2 = [15, 5, 35]; + +my $a1 = [$r1->[1]]; +my $a2 = [$r2->[1]]; +while ($a1->[-1]+$r1->[0] < 60) { + push $a1->@*, $a1->[-1]+$r1->[0]; +} +while ($a2->[-1]+$r2->[0] < 60) { + push $a2->@*, $a2->[-1]+$r2->[0]; +} +my $d1 = [map {$r1->[2]+$_} $a1->@*]; +my $d2 = [map {$r2->[2]+$_} $a2->@*]; + +for my $i (0..59) { + my $p1 = first {$a1->[$_] >= $i} 0..$a1->$#*; + my $p2 = first {$a2->[$_] >= $i} 0..$a2->$#*; + if (defined($p1) && defined($p2)) { + if ($a1->[$p1] < $a2->[$p2] && $d1->[$p1] > $d2->[$p2]) { + print "$i, "; + } + if ($a1->[$p1] > $a2->[$p2] && $d1->[$p1] < $d2->[$p2]) { + print "$i, "; + } + } +} +print "\n"; |
