diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-06-23 17:01:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-23 17:01:02 +0100 |
| commit | 56e31c94a634927308fa81e9afe3f63f6787e7fa (patch) | |
| tree | a481f276f0890c8efa3f04774bd1a588596eb789 | |
| parent | b4970fd33f91f41c173b4705a35e673c4aaacab5 (diff) | |
| parent | d638543371a7ebdd152d311846c359bec88935f0 (diff) | |
| download | perlweeklychallenge-club-56e31c94a634927308fa81e9afe3f63f6787e7fa.tar.gz perlweeklychallenge-club-56e31c94a634927308fa81e9afe3f63f6787e7fa.tar.bz2 perlweeklychallenge-club-56e31c94a634927308fa81e9afe3f63f6787e7fa.zip | |
Merge pull request #10293 from fluca1978/PWC274
PWC 274
| -rw-r--r-- | challenge-274/luca-ferrari/blog-1.txt | 1 | ||||
| -rw-r--r-- | challenge-274/luca-ferrari/blog-2.txt | 1 | ||||
| -rw-r--r-- | challenge-274/luca-ferrari/pljava/pom.xml | 72 | ||||
| -rw-r--r-- | challenge-274/luca-ferrari/raku/ch-1.raku | 35 | ||||
| -rw-r--r-- | challenge-274/luca-ferrari/raku/ch-2.raku | 55 |
5 files changed, 92 insertions, 72 deletions
diff --git a/challenge-274/luca-ferrari/blog-1.txt b/challenge-274/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..53df09edbb --- /dev/null +++ b/challenge-274/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/19/PerlWeeklyChallenge274.html#task1 diff --git a/challenge-274/luca-ferrari/blog-2.txt b/challenge-274/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..0b5d75b2eb --- /dev/null +++ b/challenge-274/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/19/PerlWeeklyChallenge274.html#task2 diff --git a/challenge-274/luca-ferrari/pljava/pom.xml b/challenge-274/luca-ferrari/pljava/pom.xml deleted file mode 100644 index ade9b2efb4..0000000000 --- a/challenge-274/luca-ferrari/pljava/pom.xml +++ /dev/null @@ -1,72 +0,0 @@ - -<project - xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > - <modelVersion>4.0.0</modelVersion> - - <groupId>PWC</groupId> - <artifactId> - PWC273 - </artifactId> - <version> - 1 - </version> - - <name>Perl Weekly Challenge 273 with package PWC273</name> - <description>Implementation of the tasks in PL/Java for PWC 273</description> - - <properties> - <project.build.sourceEncoding>US-ASCII</project.build.sourceEncoding> - </properties> - - <dependencies> - <dependency> - <groupId>org.postgresql</groupId> - <artifactId>pljava-api</artifactId> - <version>1.6.6</version> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.8.1</version> - <configuration> - <release>9</release> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>2.6</version> - <configuration> - <archive> - <manifest> - <!-- This identifies and version-stamps the jar. - Not essential, but easy and useful. --> - <addDefaultImplementationEntries> - true - </addDefaultImplementationEntries> - </manifest> - - <manifestSections> - <!-- This identifies a file in the jar named - pljava.ddr as an SQLJDeploymentDescriptor. --> - <manifestSection> - <name>pljava.ddr</name> - <manifestEntries> - <SQLJDeploymentDescriptor> - true - </SQLJDeploymentDescriptor> - </manifestEntries> - </manifestSection> - </manifestSections> - </archive> - </configuration> - </plugin> - </plugins> - </build> -</project> diff --git a/challenge-274/luca-ferrari/raku/ch-1.raku b/challenge-274/luca-ferrari/raku/ch-1.raku new file mode 100644 index 0000000000..d88b5a81a8 --- /dev/null +++ b/challenge-274/luca-ferrari/raku/ch-1.raku @@ -0,0 +1,35 @@ +#!raku + +# +# Perl Weekly Challenge 274 +# Task 1 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-274> +# + +sub MAIN( Str $sentence ) { +# 1) If a word begins with a vowel ("a", "e", "i", "o", "u"), append +# "ma" to the end of the word. +# 2) If a word begins with consonant i.e. not a vowel, remove first +# letter and append it to the end then add "ma". +# 3) Add letter "a" to the end of first word in the sentence, "aa" to + # the second word, etc etc. + + my $suffix = 'a'; + my @words; + for $sentence.split( / \s+ / ) -> $word is copy { + $word ~~ / ^ ( <[a..zA..Z]> ) .* $ /; + my $initial = $/[ 0 ].Str; + if ( $initial.lc !~~ / <[aeiou]> / ) { + $word = $word.comb[ 1 .. * ].join ~ $initial; + } + + $word ~= 'ma'; + $word ~= $suffix; + $suffix ~= 'a'; + @words.push: $word; + } + + @words.join( ' ' ).say; + +} diff --git a/challenge-274/luca-ferrari/raku/ch-2.raku b/challenge-274/luca-ferrari/raku/ch-2.raku new file mode 100644 index 0000000000..70e0d160ad --- /dev/null +++ b/challenge-274/luca-ferrari/raku/ch-2.raku @@ -0,0 +1,55 @@ +#!raku + +# +# Perl Weekly Challenge 274 +# Task 2 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-274> +# + +sub MAIN() { + + my @routes = [ [12, 11, 41], [15, 5, 35] ]; + + my @times; + my $route = 0; + + my %timetable; + + my $preferred = False; + for @routes -> $current_route { + + my ( $interval, $start_at, $time ) = $current_route; + + my $arrive_at = $start_at + $time; + my $previous_bus_start_at = 0; + + while ( $arrive_at < 120 ) { + for 0 .. 59 -> $minute { + last if $minute > $start_at; + next if $minute < $previous_bus_start_at; + %timetable{ $minute }.push: { start => $start_at, arrive => $arrive_at, route => $current_route.Str, preferred => $preferred }; + } + + $previous_bus_start_at = $start_at; + $start_at += $interval; + $arrive_at = $start_at + $time; + } + + $preferred = True; + } + + my @skip; + for %timetable.keys.sort( * <=> * ) -> $minute { + my @bus = %timetable{ $minute }.Array; + next if ( @bus.elems == 1 && ! @bus[ 0 ]<preferred> ); + + @skip.push: $minute if ( @bus.sort( { $^a<arrive> <=> $^b<arrive> } )[ 0 ]<preferred> ); + } + + + @skip.say; + + + +} |
