Perl Weekly Challenge 318: Short and to the point!

This post presents my solutions to the Perl Weekly Challenge 318.
I keep doing the Perl Weekly Challenge in order to mantain my coding skills in good shape, as well as in order to learn new things, with particular regard to Raku, a language that I love.
This week, I solved the following tasks:

Raku Implementations

PWC 318 - Task 1 - Raku Implementation

Given a string of lower case letters, find out all the groups of 3 consecutive characters.

sub MAIN( Str $string ) {
    $string.comb.unique.map( -> $char { ( $string ~~ / $char ** 3 / // '' ).Str } )
		          .grep( { $_.chars == 3 } )
		          .join( ', ' ).say;
}



This can be solved with a single line: map the unique set of chars to a regular expression that finds out a consecutive cluster of three chars, then filter out the empty strings and print out.

PWC 318 - Task 2 - Raku Implementation

Given two arrays of integers, find out if reverting a sub-array of one can lead to the other.

sub MAIN( :@a, :@b) {

    for 0 ^..^ @a.elems {
		'True'.say and exit if ( @a[ 0 .. $_ ].reverse, @a[ $_ + 1 .. * - 1 ] ).flat ~~ @b;
    }

    'False'.say;
}



The idea is to revert a subscript of the @a array, joining with the remaining items and smart matching against the other array.

The article Perl Weekly Challenge 318: Short and to the point! has been posted by Luca Ferrari on April 23, 2025