From d638543371a7ebdd152d311846c359bec88935f0 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Wed, 19 Jun 2024 11:36:32 +0200 Subject: PWC 274 Task 1 Raku done Task 2 Raku done --- challenge-274/luca-ferrari/blog-1.txt | 1 + challenge-274/luca-ferrari/blog-2.txt | 1 + challenge-274/luca-ferrari/pljava/pom.xml | 72 ------------------------------- challenge-274/luca-ferrari/raku/ch-1.raku | 35 +++++++++++++++ challenge-274/luca-ferrari/raku/ch-2.raku | 55 +++++++++++++++++++++++ 5 files changed, 92 insertions(+), 72 deletions(-) create mode 100644 challenge-274/luca-ferrari/blog-1.txt create mode 100644 challenge-274/luca-ferrari/blog-2.txt delete mode 100644 challenge-274/luca-ferrari/pljava/pom.xml create mode 100644 challenge-274/luca-ferrari/raku/ch-1.raku create mode 100644 challenge-274/luca-ferrari/raku/ch-2.raku 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 @@ - - - 4.0.0 - - PWC - - PWC273 - - - 1 - - - Perl Weekly Challenge 273 with package PWC273 - Implementation of the tasks in PL/Java for PWC 273 - - - US-ASCII - - - - - org.postgresql - pljava-api - 1.6.6 - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 9 - - - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - - - - - - true - - - - - - - pljava.ddr - - - true - - - - - - - - - - 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 +# + +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 +# + +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 ] ); + + @skip.push: $minute if ( @bus.sort( { $^a <=> $^b } )[ 0 ] ); + } + + + @skip.say; + + + +} -- cgit