Perl Weekly Challenge 117: quick and dirty
One way to let me improve my knowledge about Raku (aka Perl 6) is to implement programs in it. Unluckily, I don’t have any production code to implement in Raku yet (sob!). So, why not try solving the Perl Weekly Challenge tasks?In the following, the assigned tasks for Challenge 117.
My official solutions are available on the GitHub repository.
PWC 117 - Task 1
The first task was about finding outmissing numbered lines in a file. Something that can be very helpful if you are programming in Basic!sub MAIN( Str $file-name = 'test.txt' ) {
my %lines = $file-name.IO.lines.map: { my ( $number, $content ) = .split( ',' );
$number.Int => $content.trim;
}
say "Missing line $_ !" if %lines{ $_ }:!exists
for 1 .. %lines.keys.sort( *.Int <=> *.Int )[ * - 1 ];
}
I do read all the lines, and place them into an hash where the number is the key and the content is the rest of the line. Thenm I iterate on all numbers of lines, in particular from 1 to the max value found, and I search for that key in the hash. If the key does not exist, the line is missing.
PWC 117 - Task 2
This is something I’m not sure I’ve done right, but essentially is the moves you can get from the root of a triangle structure to the rightmost bottom. I coded the moves you can do, and then I expand the moves depending on the deep of the triangle. I’m not sure this is going to work, without any missing move, for very large triangles:sub MAIN( Int $n ) {
my @directions.push:
'R' x $n
, 'LH' x $n
, 'L' x $n ~ 'H' x $n
, 'LH' x ($n -1) ~ 'R' x ($n - 1 )
, 'R' x ($n - 1) ~ 'LH' x ($n - 1 )
, 'R' x ($n -1) ~ 'LH' x ($n - 1);
@directions.unique.say;
}