The Weekly Challenge ‐ Perl and Raku

CY's Short Notes on The Weekly Challenge (latest formally: Week #139)

If you want to challenge yourself on programming, especially on Perl and/or Raku, go to, code the latest challenges, submit codes on-time (by GitHub or email).

Do tell me, if I am wrong or you strongly oppose my statements!

I put some reflections from what I learnt from writing the tasks (also from the review) or what I think I should be going to do. The content is too short to be a blogpost.

The reflections are placed in reverse chronological order.

Week #166 K-Directory Diff

$ perl
ok 1
  ../../../cha**  ../../../cha**
ok 2
  ../../../cha**  ../../../cha**  ../../../cha**
                        blog.txt        blog.txt
ok 3
  ../../../cha**  ../../../cha**  ../../../cha**  ../../../cha**  ../../../cha**  ../../../cha**  ../../../cha**  ../../../cha**
           perl/           perl/                           perl/           perl/           perl/           perl/           perl/
                          julia/                          julia/                                                                
                         python/                                                                         python/         python/
                                                           java/           java/                                           java/
                                                                                    common-lisp/    common-lisp/    common-lisp/
                          README          README          README          README          README          README          README
                                                        blog.txt        blog.txt                                                
                                                                                                        BLOG.txt        BLOG.txt
ok 4

Week #147

I have missed the interesting TWC task "Palindromic Tree"(Week #145) and "Curious Fraction Tree"(Week #146). □

Week #139 Long Primes

I have forgotten the Fermat's little theorem. My number theory is not as good as I thought.

Thanks for the reviewer of Team TWC Colin's comment(link to the review). □

Week #132 (about Week #129)

After reading Perl solutions review of the “The Weekly Challenge - 129” by Colin: I noticed the "carry one" situation of Task 2 but did not implemented it. My submission is not counted for the reviewer. Anyway, it reminds me when I code and feel confused next time, I can give options for possible confusing conditions if time allows, especially for professional work. :) □

Week #127 Disjoint Sets and Conflict Intervals

I would have a headache whenever the intervals-tasks were released. I have gained confidence now and both tasks were okay for me. □

Week #126 Count Number and CY's Puzzle Creation

For Task 1 Count Number: Abigail's way of doing it is superb. (I write this down because I learn more math again.)

For CY's Puzzle Creation:

Before the task official released, I had already written a script, thus I got more free time. Following Lubos Kolouch's suggestion on the Facebook group, I wrote a playable interface.

Lubos's suggestion had been very beneficial for me. I got an opportunity to learn Getopt::Long and IO::Prompter. □

Week #125 CY's Puzzle Creation "Pythagorean Triples"

The official review is out and you may read it from the link.

This puzzle looks lying on the sweet spot of "not difficult", "not complicated" but "requiring thoughts".

My solution is a simple brute-force. Originally I would like to using the (u2-v2, uv, u2+v2) factorization to solve it. But I was tired, hence giving a solution with few lines. Maybe the factorization will be more complex to implement. I learn some new ways ([1] and [2]) to generate the Pythagorean Triples from the teammates' solutions. □

Week #124 "The Olympics Week"

Task 1 is completed while I thought my time left this week was impossible for a reasonable attemption of Task 2.

How to draw a circle via ASCII art? I did not attempt this though. My approach is using square to represent the "Sun sign" (the circle) of the Venus symbol, in order to complete the task fast.

For the Task 2, its data is kept at a public page and a "protected" page. I understand swapping cannot give the exact solution in many situations and would like to calculate the range of applicable numbers with respect to the size of the set, given that the numbers are integers. My current conjecture is, if the numbers given are positive integers, the appliable range of "swapping approach" is 1 to (2*A087940)-1. (See my notes). However, I ever haven't completed cases when there are duplicate terms.

See the codes.

Again, on the Task 2, I would compare to the speed for the script compared to James Smith's [blog] and check the accuracy of the script through the set of code by Roger Bell-West [blog].

Lastly, thanks Mohammand's mention on the section "Headlines" about my improvement through The Weekly Challenge. I am very glad that I find the TWC community.

Stay healthy and alert! □

Week #118 Adventure of Knight and Week #121 Travelling Salesman


In previous blogpost on Week 118, I mentioned that "...I have improved my code by a very trivial action (reducing calling to &compare_mini by moving a conditional).". The performance changed is shown below:

CaseNumber of SpotsTime
Number of Permutations
Task specific60.066 sec0.025 sec720
I94.263 sec2.760 sec362,880
II1046 sec30.563 sec3,628,800
III12130 min76 min 50.364 sec479,001,600

Here is what changed:


For Week #121 Task 2, I had just been lazy and use permutations again:

my $v = chr(ord("A")+$N-2); my $iter = permutations(['A'..$v]); while (my $c = $iter->next) { my $d = calc_dist($c); if (defined($d) && $d <= $min) { # [*] if ($d < $min) { @arr_min = (); $min = $d; } push @arr_min, $c; } }

Using a similar and a logically same trick, I have improved my codes (place marked with [*]):

sub calc_dist { my @seq = @{$_[0]}; my $dist = 0; $dist += $M->[0][ alp2n($seq[0]) ]; for my $i (0..$#seq-1) { $dist += $M->[ alp2n($seq[$i]) ][ alp2n($seq[$i+1]) ]; return undef if $dist >= $min; # [*] } $dist += $M->[alp2n($seq[-1])][0]; }

CaseNumber of CitiesTime
Number of Permutations
I1124.5 sec16.5 sec3,628,800
II125 min 7 sec3 min 30 sec39,916,800

Here was the story of improving efficiency. However, after all, my codes are not efficient enough. My practice target is following the team member James Smith's elegant cache solution on these two tasks to write Java versions.

written on mid-July 2021

Except from images and codes from personnels, the content of this page is released under a copyleft spirit. One may share (full or partial) content of this page on other platform if you share it under the free and open content spirit.

links: The Weekly Challenge Team Repository, Team Website

Contact on twitter: @e7_87.

Created Date: 21st July, 2021.