The Weekly Challenge: 402

6 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: Letters Only Hex

10. TASK #2: Circular String Rotations

HEADLINES


Welcome to the Week #402 of The Weekly Challenge.

Welcome aboard, Benjamin Kincses, and thanks for your first contributions in Perl. We now have 340 members in Team PWC on record.

The festive month is about to start. It is the month when I take remaining days off my total annual holidays. Although I don’t celebrate Christmas but I always look forward to it. I like the whole celebration moment where ever I go during this period. Personally it is busiest time of the year as I have to run the Advent Calendar. Also it is the time to reflect on how we performed in year 2026.

Talking about contributions, I noticed Postscript made it to the TOP #10 guest languages by pushing Java down. Congratulation to all Postscript contributors.

One more interesting stats, last week we crossed 15K+ pull requests for the weekly challenge. Also 50K+ commits to the repository.

Below is my contributions to the Week #401.

[Task #1 - Perl]: source code


sub fraction_calc($expr) {
    my $sum = Math::BigRat->new('0/1');
    $sum += Math::BigRat->new($_) for $expr =~ /[+-]?\d+\/\d+/g;
    return $sum->numerator . '/' . $sum->denominator;
}

[Task #2 - Perl]: source code


sub extract_digits($str) {
    my %c;
    $c{$_}++ for split //, $str;

    my %n = (
        0 => $c{z} // 0,
        2 => $c{w} // 0,
        4 => $c{u} // 0,
        6 => $c{x} // 0,
        8 => $c{g} // 0,
    );
    $n{1} = ($c{o} // 0) - $n{0} - $n{2} - $n{4};
    $n{3} = ($c{h} // 0) - $n{8};
    $n{5} = ($c{f} // 0) - $n{4};
    $n{7} = ($c{s} // 0) - $n{6};
    $n{9} = ($c{i} // 0) - $n{5} - $n{6} - $n{8};

    return join '', map { "$_" x $n{$_} } 0 .. 9;
}

[Task #1 - Raku]: source code


sub fraction-calc($expr) {
    my $sum = 0/1;
    $sum += .Rat for $expr ~~ m:g/<[+-]>?\d+\/\d+/;
    return "{$sum.numerator}/{$sum.denominator}";
}

[Task #2 - Raku]: source code


sub extract-digits($str) {
    my %c;
    %c{$_}++ for $str.comb;

    my %n =
        0 => %c<z> // 0,
        2 => %c<w> // 0,
        4 => %c<u> // 0,
        6 => %c<x> // 0,
        8 => %c<g> // 0,
    ;
    %n{1} = (%c<o> // 0) - %n{0} - %n{2} - %n{4};
    %n{3} = (%c<h> // 0) - %n{8};
    %n{5} = (%c<f> // 0) - %n{4};
    %n{7} = (%c<s> // 0) - %n{6};
    %n{9} = (%c<i> // 0) - %n{5} - %n{6} - %n{8};

    return (0..9).map({ "$_" x %n{$_} }).join;
}

[Task #1 - Python]: source code


def fraction_calc(expr: str) -> str:
    total = Fraction(0, 1)
    for token in re.findall(r"[+-]?\d+/\d+", expr):
        total += Fraction(token)
    return f"{total.numerator}/{total.denominator}"

[Task #2 - Python]: source code


def extract_digits(s: str) -> str:
    c = Counter(s)

    n = {
        0: c["z"],
        2: c["w"],
        4: c["u"],
        6: c["x"],
        8: c["g"],
    }
    n[1] = c["o"] - n[0] - n[2] - n[4]
    n[3] = c["h"] - n[8]
    n[5] = c["f"] - n[4]
    n[7] = c["s"] - n[6]
    n[9] = c["i"] - n[5] - n[6] - n[8]

    return "".join(str(d) * n[d] for d in range(10))

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   
   397       41       20       15   
   398       44       22       16   
   399       33       16       11   
   400       36       20       11   
   401       30       17       11   


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

  Week      Guests       Contributions       Languages   
   397       15       81       31   
   398       15       82       27   
   399       10       40       15   
   400       13       51       20   
   401       7       26       12   

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     (4759)
 2. Rust       (1268)
 3. C          (1087)
 4. Haskell    (981)
 5. Ruby       (972)
 6. Lua        (950)
 7. C++        (769)
 8. Go         (742)
 9. JavaScript (665)
10. Postscript (537)

Blogs with Creative Title


1. Fractional Reconstruction by Arne Sommer.

2. Scrambled Fractions by Jorg Sommrey.

3. Adding Fractions and Subtracting Digits by Matthias Muth.

4. Zydeco? Why Zydeco? by Packy Anderson.

5. Fractional Reconstruction by Roger Bell_West.

6. Mixed fractions by Simon Green.

GitHub Repository Stats


1. Commits: 52,268 (+64)

2. Pull Requests: 15,017 (+25)

3. Contributors: 281

4. Fork: 352

5. Stars: 221


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 - 401 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


Benjamin Kincses, an experienced Perl hacker joined Team PWC.

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 #401.

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

Task 1: Letters Only Hex

Submitted by: Mohammad Sajid Anwar

You are given a string representing a decimal integer >= 1 without leading zeros.

Write a script that to convert the given string into its uppercase hexadecimal representation. Replace every digit ‘0’ with the letter ‘O’, also replace every digit ‘1’ with the letter ‘I’. The resulting string should only contain characters: ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘I’, and ‘O’.

Example 1

Input: $expr = "16"
Output: "IO"

Example 2

Input: $expr = "10"
Output: "A"

Example 3

Input: $expr = "2748"
Output: "ABC"

Example 4

Input: $expr = "4098"
Output: ""

Hex equivalent: 1002 => IOO2
Mostly valid characters (1, 0, 0), but fails because of a single '2'.

Task 2: Circular String Rotations

Submitted by: Mohammad Sajid Anwar

You are given a string containing lowercase English letters and directions array in the form [direction, amount]. The direction 0 is left shift and direction 1 is right shift.

Write a script to apply the sequence of left and right rotations to the given string and return the final string.

Example 1

Input: $str = "hello"
       @directions = ([1, 3], [0, 3])
Output: "hello"

Operation 1: [1,3]
Right 1: "ohell"
Right 2: "lohel"
Right 3: "llohe"

Operation 2: [0, 3]
Left 1: "lohel"
Left 2: "ohell"
Left 3: "hello"

Example 2

Input: $str = "abcd"
       @directions = ([1, 6])
Output: "cdab"

Example 3

Input: $str = "coding"
       @directions = ([0, 4], [1, 2])
Output: "dingco"

Example 4

Input: $str = "planet"
       @directions = ([0, 11], [1, 4], [0, 2])
Output: "netpla"

Example 5

Input: $str = "z"
       @directions = ([0, 5], [1, 9])
Output: "z"

Example 6

Input: $str = "jubilee"
       @directions = ([0, 12], [1, 3], [0, 9])
Output: "leejubi"

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 6th December 2026.