Raku Solutions Weekly Review
Getting in Touch
Email › Email me (Andrew) with any feedback about this review.
GitHub › Submit a pull request for any issues you may find with this page.
Twitter › Join the discussion on Twitter!
We’d greatly appreciate any feedback you’d like to give.
The first task of the week was mostly solved by calling the
combinations method on a range of integer numbers. It was quite educating to learn how this method actually works and learn that it only returns unique elements, so it is absolutely suitable for the task at hand, and it does all the required work for us.
There are a couple of solutions that first generate a bigger row of combinations and then use
grep to filter the ones we need. These solutions immediately look different compared to those that use
combinations, which only proves that Raku offers us more than we can sometimes imagine. I am sure you will enjoy looking at the code.
Please checkout the detailed examination of each and every Raku solutions of the Task 1, Week 67.
In the keypad task, the majority of the solutions include a mapping data structure, but there are different variations of it. Let me demonstrate just a few of them:
Lists in an array, where the digit is the index in the array:
my @keypad = ' ', < _ , @>, < a b c >, < d e f >, < g h i >, < j k l >, < m n o >, < p q r s >, < t u v >, < w x y z >;
The other approaches include hashes where the digits are indices. But it varies further. Here is an example, where the values are the strings you see on the keys.
my %h = 2 => 'abc', 3 => 'def', 4 => 'ghi', 5 => 'jkl', 6 => 'mno', 7 => 'pqrs', 8 => 'tuv', 9 => 'wxyz';
Or, for example, the values are lists of separate characters within the fancy
my %phone = 1 => <_ , @>, 2 => <a b c>, 3 => <d e f>, 4 => <g h i>, 5 => <j k l>, 6 => <m n o>, 7 => <p q r s>, 8 => <t u v>, 9 => <w x y z>;
Or a more traditional code with quotes and square brackets:
my %phone_keys = ( '1' => ['_', ',', '@'], '2' => ['a', 'b', 'c'], '3' => ['d', 'e', 'f'], '4' => ['g', 'h', 'i'], '5' => ['j', 'k', 'l'], '6' => ['m', 'n', 'o'], '7' => ['p', 'q', 'r', 's'], '8' => ['t', 'u', 'v'], '9' => ['w', 'x', 'y', 'z'], '*' => ['_'], '0' => [''], '#' => [''], );
And you really want to see another approach, where the list is partially generated using the
rotor method. It makes a series of three-letter lists from a range
[|('a'..'o').rotor(3), <p q r s>, <t u v>, <w x y z>]
More on the interesting things found in the solutions of Task 2, Week 67 are in this video.
Andrew Shitov, Arne Sommer, Colin Crain, Donald Hunter, Jaldhar H. Vyas, Javier Luque, Laurent Rosenfeld, Luca Ferrari, Mohammad S Anwar and Shahed Nooshmand.
If you want to participate to The Weekly Challenge, please contact us at firstname.lastname@example.org.