The Weekly Challenge: 393

4 min read
← Back to Challenges

TABLE OF CONTENTS


  1. HEADLINES

  2. SPONSOR

  3. RECAP

  4. PERL REVIEW

  5. RAKU REVIEW

  6. CHART

  7. NEW MEMBERS

  8. GUESTS

  9. TASK #1: Pythagoras Multiplied

10. TASK #2: Prime Step

HEADLINES


Welcome to the Week #393 of The Weekly Challenge.

Thank you, Ulrich Rieke, for suggesting two fun tasks. You made it a lot easier for me.

I would also like to thank, Roger Bell_West, for reviewing the task. You have saved me from embarrassment so many times.

Below is my contributions to the Task #1 of Week #392.

Perl: source code


sub convert_palindrome($str) {
    for my $len (reverse 1 .. length $str) {
        my $prefix = substr($str, 0, $len);
        return reverse(substr($str, $len)) . $str if $prefix eq reverse $prefix;
    }
}

Raku: source code


sub convert-palindrome(Str $str) {
    for (1 .. $str.chars).reverse -> $len {
        my $prefix = $str.substr(0, $len);
        return $str.substr($len).flip ~ $str if $prefix eq $prefix.flip;
    }
}

Python: source code


def convert_palindrome(s):
    for length in range(len(s), 0, -1):
        prefix = s[0:length]
        if prefix == prefix[::-1]:
            return s[length:][::-1] + s

Thank you Team PWC, once again.

Happy Hacking!!



Last 5 weeks mainstream contribution stats. Thank you Team PWC for your support and encouragements.

  Week      Perl       Raku       Blog   
   388       39       19       15   
   389       41       18       14   
   390       37       16       15   
   391       39       20       16   
   392       39       21       14   


Last 5 weeks guest contribution stats. Thank you each and every guest contributors for your time and efforts.

  Week      Guests       Contributions       Languages   
   388       12       70       25   
   389       13       70       23   
   390       11       28       10   
   391       10       50       10   
   392       12       45       15   

TOP 10 Guest Languages


Do you see your favourite language in the Top #10? If not then why not contribute regularly and make it to the top.

 1. Python     (4636)
 2. Rust       (1234)
 3. C          (1073)
 4. Haskell    (964)
 5. Ruby       (945)
 6. Lua        (929)
 7. C++        (755)
 8. Go         (732)
 9. JavaScript (654)
10. Java       (532)

Blogs with Creative Title


1. Convert Product by Arne Sommer.

2. Go hang a salami, I’m a lasagna hog! by Packy Anderson.

3. Palindromes and products by Peter Campbell Smith.

4. Extruded Palindrome Product by Roger Bell_West.

5. The palindromic length by Simon Green.

GitHub Repository Stats


1. Commits: 51,469 (+81)

2. Pull Requests: 14,750 (+30)

3. Contributors: 281

4. Fork: 352

5. Stars: 220


With start of Week #355, we have a new sponsor Marc Perry until the end of year 2026. Having said we are looking for more sponsors so that we can go back to weekly winner. If anyone interested please get in touch with us at perlweeklychallenge@yahoo.com. Thanks for your support in advance. You can find more informations here.

RECAP


Quick recap of The Weekly Challenge - 392 by Mohammad Sajid Anwar.

PERL REVIEW


If you missed any past reviews then please check out the collection.

RAKU REVIEW


If you missed any past reviews then please check out the collection.

CHART


Please take a look at the charts showing interesting data.

I would like to THANK every member of the team for their valuable suggestions. Please do share your experience with us.

NEW MEMBERS


Please find out How to contribute?, if you have any doubts.

Please try the excellent tool EZPWC created by respected member Saif Ahmed of Team PWC.

GUESTS


Please check out the guest contributions for the Week #392.

Please find past solutions by respected guests. Please share your creative solutions in other languages.

Task 1: Pythagoras Multiplied

Submitted by: Ulrich Rieke

You are given a positive integer n.

Find the number of all positive integer triplets (a, b, c) so that a^2 + b^2 = c^2 and a, b and c are integers <= n.

Example 1

Input: $n = 20
Output: 12

(3,4,5),  (4,3,5),   (5,12,13),(6,8,10),
(8,6,10), (8,15,17), (9,12,15),(12,5,13),
(12,9,15),(12,16,20),(15,8,17),(16,12,20)

Example 2

Input: $n = 7
Output: 2

(3,4,5),(4,3,5)

Example 3

Input: $n = 1
Output: 0

Example 4

Input: $n = 15
Output: 8

Example 5

Input: $n = 30
Output: 22

Task 2: Prime Step

Submitted by: Ulrich Rieke

You are given a string with English alphabetic characters only.

What is the absolute difference of the sum of the ASCII values of the characters in the string to the nearest prime number?

Example 1

Input: $str = "hello"
Output: 9

The ordinal values of "hello" are [104,101,108,108,111], summing up to 532.
The nearest prime number to 532 is 523, resulting in an absolute difference of 9.

Example 2

Input: $str = "football"
Output: 2

Starting with the values [102,111,111,116,98,97,108,108] and the sum 841.
We find 839 as the nearest prime number, so the difference is 2.

Example 3

Input: $str = "a"
Output: 0

Example 4

Input: $str = "challenge"
Output: 2

The ordinal values of "challenge" are [99, 104, 97, 108, 108, 101, 110, 103, 101], which sum up to 931.
The nearest prime number to 931 is 929, so the difference is 2.

Example 5

Input: $str = "perl"
Output: 2

The ordinal values of "perl" are [112, 101, 114, 108], summing up to 435.
Nearest prime is 433, so the difference is 2.

By submitting a response to the challenge you agree that your name or pseudonym, any photograph you supply and any other personal information contained in your submission may be published on this website and the associated mobile app. Last date to submit the solution 23:59 (UK Time) Sunday 4th October 2026.