The Weekly Challenge - 270

Monday, May 20, 2024| Tags: Perl, Raku

TABLE OF CONTENTS


01. HEADLINES

02. SPONSOR

03. RECAP

04. PERL REVIEW

05. RAKU REVIEW

06. CHART

07. NEW MEMBERS

08. GUESTS

09. TASK #1: Special Positions

10. TASK #2: Equalize Array


HEADLINES


Welcome to the Week #270 of The Weekly Challenge.

Thank you, Andrew Shitov, for yet another Raku review for Week #268.

Did you notice, in recent time, we are exploring guest languages more than the primary languages Perl and Raku?

It was a close contest last week. We had 78 guest contributions as compare to 74 regular contributions, if we take blogs out of the race.

Let us all celebrate the top Guest Contributors as listed below:

1) Ali Moradi: Go, Java, Modula 3, Ruby, Standard ML
2) Asher Harvey-Smith: APL, BQN, Haskell, Hy, J, Nu
3) David Ferrone: C, JavaScript, Python, Rust
4) Eric Cheung: Python
5) Lubos Kolouch: Python
6) Luca Ferrari: Java, PostgreSQL, Python
7) Nelo Tovar: Bash
8) Packy Anderson: Elixir, Python
9) PokGoPun: Go, Python
10) Roger Bell_West: Crystal, JavaScript, Kotlin, Lua, PostScript, Python, Ruby, Rust, Scala
11) Simon Green: Python
12) Steven Wilson: Python
13) Ulrich Rieke: C++, Haskell, Rust

I have reached out to the recent champions with regard to the prize money. I sent email to Nelo Tovar, Mustafa Aydin, Asher Harvey-Smith and Reinier Maliepaard on 14th May 2024. So far I received reply back from Reinier Maliepaard only. Thank you Reinier for getting back to me and successfully transferred the prize money. I would like to mention, PayPal is also an option for payment if you prefer. I would request please check out Spam in case it went straight there. Looking forward to your reply. Just in case, you can even reach out to me on perlweeklychallenge@yahoo.com.



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

  Week      Perl       Raku       Blog   
   265       54       32       26   
   266       55       29       24   
   267       50       27       24   
   268       48       31       26   
   269       44       30       24   

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

  Week      Guests       Contributions       Languages   
   265       12       52       16   
   266       12       53       16   
   267       14       58       20   
   268       15       75       26   
   269       13       78       24   

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     (2514)
 2. Ruby       (684)
 3. Haskell    (668)
 4. Rust       (634)
 5. Lua        (602)
 6. C          (538)
 7. C++        (508)
 8. JavaScript (414)
 9. Go         (363)
10. BQN        (336)

Blogs with Creative Title


1. Distribute Or… by Arne Sommer.

2. Two of Us Distributing Elements by Bob Lied.

3. Bits and Bins by Jorg Sommrey.

4. at the last time I did! by Luca Ferrari.

5. Bitwise Distribution by Packy Anderson.

6. Bits distribution by Peter Campbell Smith.

7. The Bitwise Elements by Roger Bell_West.

8. Elements or something by Simon Green.


GitHub Repository Stats


1. Commits: 38,133 (+82)

2. Pull Requests: 10,102 (+33)

3. Contributors: 244

4. Fork: 309 (+1)

5. Stars: 172



With start of Week #268, we have a new sponsor Lance Wicks for the entire year 2024. 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.


RECAP


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


PERL REVIEW


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


RAKU REVIEW


Please checkout Raku solutions review of The Weekly Challenge - 268 by Andrew Shitov.

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

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


Task 1: Special Positions

Submitted by: Mohammad Sajid Anwar

You are given a m x n binary matrix.

Write a script to return the number of special positions in the given binary matrix.

A position (i, j) is called special if $matrix[i][j] == 1 and all other elements in the row i and column j are 0.

Example 1

Input: $matrix = [ [1, 0, 0],
                   [0, 0, 1],
                   [1, 0, 0],
                 ]
Output: 1

There is only one special position (1, 2) as $matrix[1][2] == 1
and all other elements in row 1 and column 2 are 0.

Example 2

Input: $matrix = [ [1, 0, 0],
                   [0, 1, 0],
                   [0, 0, 1],
                 ]
Output: 3

Special positions are (0,0), (1, 1) and (2,2).

Task 2: Equalize Array

Submitted by: Mohammad Sajid Anwar

You are give an array of integers, @ints and two integers, $x and $y.

Write a script to execute one of the two options:

Level 1:
Pick an index i of the given array and do $ints[i] += 1

Level 2:
Pick two different indices i,j and do $ints[i] +=1 and $ints[j] += 1.

You are allowed to perform as many levels as you want to make every elements in the given array equal. There is cost attach for each level, for Level 1, the cost is $x and $y for Level 2.

In the end return the minimum cost to get the work done.

Example 1

Input: @ints = (4, 1), $x = 3 and $y = 2
Output: 9

Level 1: i=1, so $ints[1] += 1.
@ints = (4, 2)

Level 1: i=1, so $ints[1] += 1.
@ints = (4, 3)

Level 1: i=1, so $ints[1] += 1.
@ints = (4, 4)

We perforned operation Level 1, 3 times.
So the total cost would be 3 x $x => 3 x 3 => 9

Example 2

Input: @ints = (2, 3, 3, 3, 5), $x = 2 and $y = 1
Output: 6

Level 2: i=0, j=1, so $ints[0] += 1 and $ints[1] += 1
@ints = (3, 4, 3, 3, 5)

Level 2: i=0, j=2, so $ints[0] += 1 and $ints[2] += 1
@ints = (4, 4, 4, 3, 5)

Level 2: i=0, j=3, so $ints[0] += 1 and $ints[3] += 1
@ints = (5, 4, 4, 4, 5)

Level 2: i=1, j=2, so $ints[1] += 1 and $ints[2] += 1
@ints = (5, 5, 5, 4, 5)

Level 1: i=3, so $ints[3] += 1
@ints = (5, 5, 5, 5, 5)

We perforned operation Level 1, 1 time and Level 2, 4 times.
So the total cost would be (1 x $x) + (4 x $y) => (1 x 2) + (4 x 1) => 6


Last date to submit the solution 23:59 (UK Time) Sunday 26th May 2024.


SO WHAT DO YOU THINK ?

If you have any suggestions or ideas then please do share with us.

Contact with me