## 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 https://theweeklychallenge.org,
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 ch-2.pl 1..4 ok 1 ../../../cha** ../../../cha** -------------------------------- julia/ blog.txt ok 2 ../../../cha** ../../../cha** ../../../cha** ------------------------------------------------ julia/ blog.txt blog.txt README ok 3 ../../../cha** ../../../cha** ../../../cha** ../../../cha** ../../../cha** ../../../cha** ../../../cha** ../../../cha** -------------------------------------------------------------------------------------------------------------------------------- perl/ perl/ perl/ perl/ perl/ perl/ perl/ julia/ julia/ python/ python/ python/ dart/ awk/ bash/ cpp/ java/ java/ java/ node/ smalltalk/ common-lisp/ common-lisp/ common-lisp/ README README README README README README README blog.txt blog.txt BLOG.txt BLOG.txt BLOG1.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 (u^{2}-v^{2}, uv, u^{2}+v^{2}) 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

##### Performance

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:

Case | Number of Spots | Time before | Time after | Number of Permutations |
---|---|---|---|---|

Task specific | 6 | 0.066 sec | 0.025 sec | 720 |

I | 9 | 4.263 sec | 2.760 sec | 362,880 |

II | 10 | 46 sec | 30.563 sec | 3,628,800 |

III | 12 | 130 min | 76 min 50.364 sec | 479,001,600 |

---

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 [*]):

subcalc_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]; }

Case | Number of Cities | Time before | Time after | Number of Permutations |
---|---|---|---|---|

I | 11 | 24.5 sec | 16.5 sec | 3,628,800 |

II | 12 | 5 min 7 sec | 3 min 30 sec | 39,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.