perlweeklychallenge-club

Activity, over time

Daily observations from the public event archive.

Attention

Daily stars & forks

Loading attention chart

Star accumulation

Cumulative stars

Loading star accumulation chart

Pull requests

Daily opens & merges

Loading pull requests chart

Conversations

Daily issues & comments

Loading conversations chart

Community

Daily accounts & reviews

Loading community chart

Releases

Daily releases

Loading releases chart

Mentions

4posts · 30d
Nov 30 posts
  1. Weekly Challenge: An average reflection Weekly Challenge 397 Each week Mohammad S. Anwar sends out The Weekly Challenge, a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. Unless otherwise stated, Copilot (and other AI tools) have NOT been used to generate the solution. It's a great way for us all to practice some coding. Challenge, My solutions Task 1: Absent Smallest Positive You are given an array of integers. Write a script to return the smallest absent positive integer such that it is strictly greater than the average of all elements in the given array. My solution This is relatively straight forward. I start by calculating the average and storing it in the variable average. The result variable one more than the average or 1 if the average is less than 1. I then have a loop that increments result if it is in the ints list (array in Perl). def asp(ints: list[int]) -> int: average = sum(ints) // len(ints) result = max(1, average + 1) while result in ints: result += 1 return result The Perl code follows similar logic, using some functions from the List::Util module. use List::Util qw(any max sum); sub main (@ints) { # Calculate the average my $average = sum(@ints) / scalar(@ints); my $result = max( 1, int($average) + 1 ); ++$result while ( any { $_ == $result } @ints ); say $result; Examples $ ./ch-1.py 1 2 4 5 6 7 $ ./ch-1.py -5 -2 -1 3 1 $ ./ch-1.py 1 2 3 4 $ ./ch-1.py 2 3 7 8 6 $ ./ch-1.py 1 1 1 10 4 Task 2: Binary Reflection You are given an array of integers. Write a script to sort the given array in ascending order based on the binary reflection of each element. If two different numbers have the same binary reflection, the smaller original number should appear first. My solution For this task, I create a function called calc_binary_reflection. Given an integer i, it will convert it to a binary value ([2:] strips the 0b in that string), reverses it and converts to back to an integer. def calc_binary_reflection(i: int) -> int: b = bin(i)[2:] return int(b[::-1], 2) The main function does a double sort. The inner sort ensures that integers with the same reflection integer are sorted numerically, while the outer sort uses the above function. def binary_reflection(ints: list[int]) -> list[int]: return sorted(sorted(ints), key=calc_binary_reflection) For the Perl solution, I can achieve the same functionality with a single call to the sort function. sub calc_binary_reflection($i) { my $b = sprintf "%b", $i; return oct( "0b" . reverse($b) ); } sub main (@ints) { my @sorted_ints = sort { calc_binary_reflection($a) <=> calc_binary_reflection($b) || $a <=> $b } @ints; say "(" . join( ", ", @sorted_ints ) . ")"; } Examples $ ./ch-2.py 3 6 12 (3, 6, 12) $ ./ch-2.py 1 2 4 8 (1, 2, 4, 8) $ ./ch-2.py 7 8 9 10 (8, 10, 7, 9) $ ./ch-2.py 5 9 15 17 (5, 9, 15, 17) $ ./ch-2.py 11 13 14 19 (14, 13, 11, 19)

  2. DEV · · @szabgab

    Perl 🐪 Weekly #795 - What is Randal Schwartz up to now? --- title: Perl 🐪 Weekly #795 - What is Randal Schwartz up to now? published: true description: tags: perl, news, programming canonical_url: perlweekly.com series: perl-weekly --- Originally published at Perl Weekly 795 Hi there! I'd like to welcome myself back home in Israel after a long vacation in Korea and Japan. It was awesome, but we reached the conclusiong that next time we should do it when we are younger... One of the highlights of the trip was the talking to people. It is of course mostly service providers and fellow travelers, but in Seoul we managed to meet some local tech people. Unfortunately I could not manage to arrange a meeting with any of the Perl people there. I felt that as a missed opportunity. Anyway, we have the online events where we do have some time to chat which I find extremely satisfying. You can also join the <a href="live.code-maven.com">Perl-related events</a> or for that matter <a href="live.code-maven.com">any event</a>. I'd also like to encourage you to offer a presentation on some topic that is dear to you. It can be Perl. It can be AI. It can be any of other other topics we already cover. We can even discuss topics we don't yet cover. Talk to me! One particular event that was just announced is the one by Randal Schwartz, you know, the guy from the books 'Learning Perl', 'Programming Perl', and a few others. The title is <a href="luma.com">Synthetic Scars: Giving Autonomous AI Agents the Battle-Tested Memory of a Senior Engineer</a>. We also have a new episode of <a href="underbar.cpan.io">Underbar</a>. Enjoy your week! -- Your editor: Gabor Szabo. Announcements Modern Perl Tips ![Reddit](reddit.com)by Dave Cross ![LinkedIn](linkedin.com) Dave wrote: "Talking to Perl programmers, I’ve noticed how easy it is to miss new additions to the language. We learn Perl, get comfortable with it, and get on with writing code. Meanwhile, Perl keeps moving<br>Modern Perl Tips is a chance to catch up a little at a time. Each tip takes a useful feature you might not have come across, shows how it helps with an everyday problem, and points you towards the documentation. You might discover a clearer way to write something you’ve been doing for years." --- Articles Adventures in Real-Time MIDI ![Reddit](reddit.com)by Gene Boggs Gene writes: "Since discovering Perl real-time MIDI and writing about creating async drums with it, I’ve dug deeper into what’s possible. I have a few music and MIDI modules on CPAN and like to put them to use in real time, now that I have been enlightened by zen master John Barrett. Ha :D" URI::PackageURL 2.26 released: PURL and VERS for Perlby Giuseppe Di Terlizzi URI-PackageURL implements two specifications that are becoming central to software supply-chain security: PURL (Package URL, a uniform way to identify a software package across ecosystems ) and VERS ((Version Range, a universal notation for version ranges) NetAddr::IP 4.080_05: Please Smoke Testby Dean Hamstead ![LinkedIn](linkedin.com) Dean writes: "NetAddr::IP 4.079 was released in 2016 and has sat there since. I have started working on it recently, and 4.080_05 is the fifth trial release since. It is on CPAN now, and the tarball is ready for you to install!" pperl 0.6.23 - RANT, REPL and SPEEDby Richard C. Jelinek ![LinkedIn](linkedin.com) pperl aka. perl implemented in Rust. Context::Vars: Perl variables with context scopeby Robert Acock Context::Vars gives you a variable that holds a value per context, and the context follows the work: into every sub called, into callbacks, and across await. CGI From 1993 Still Powers Your AI Agents Today. ![Reddit](reddit.com)by Gal Ratner Some history and why Perl won and then lost the battle. HAMT: persistent maps, sets and vectors for Perlby Robert Acock HAMT is a new CPAN distribution that gives Perl three persistent containers: HAMT::Map, HAMT::Set and HAMT::Vector. "Persistent" here means an update never changes the container you call it on. It returns a new one, and the old one stays exactly as it was. Time::Keeper: Time goes by so slowlyby Robert Acock Time::Keeper is a new CPAN distribution for dates and times. A value is an instant and the zone it is read in, and that is the whole of it: no state to mutate, no locale object, no copy of the zone rules. It covers the ground Time::Piece and DateTime cover between them, and a method that would change a value hands back a new one and leaves the old one as it was. --- Discussion Doom in Perl 100%DOOM, written in Perl 5.44. The engine stays in Perl. SDL2 is only the window, the sound, and the keyboard. Perl-Magpie.org (CPAN Tester site that works) Perl and CVEs - another source to scan Rust is the Perl of the 21st century --- Podcast Configure - The Underbar, episode 11"During the Perl Toolchain Summit 2026 in Vienna, we interviewed Merijn Brand, the Configure maintainer, about this indispensable piece of the Perl build setup." --- Grants PEVANS Core Perl 5: Grant Report for September 2026by Paul Evans Maintaining Perl 5 Core (Dave Mitchell): September 2026by Dave Mitchell Maintaining Perl (Tony Cook) September 2026by Tony Cook --- The Weekly Challenge <a href="theweeklychallenge.org">The Weekly Challenge</a> by <a href="manwar.org">Mohammad Sajid Anwar</a> will help you step out of your comfort-zone. You can even win prize money of $50 by participating in the weekly challenge. We pick one champion at the end of the month from among all of the contributors during the month, thanks to the sponsor Marc Perry. The Weekly Challenge - 396by Mohammad Sajid Anwar ![LinkedIn](linkedin.com) Welcome to a new week with a couple of fun tasks "Finishing Order" and "Trionic Array". If you are new to the weekly challenge then why not join us and have fun every week. For more information, please read the <a href="theweeklychallenge.org">FAQ</a>. RECAP - The Weekly Challenge - 395by Mohammad Sajid Anwar ![LinkedIn](linkedin.com) Enjoy a quick recap of last week's contributions by Team PWC dealing with the "Complex Number" and "Word Squares" tasks in Perl and Raku. You will find plenty of solutions to keep you busy. TWC395by Ali Moradi Ali shares pragmatic and comprehensive solutions in Perl for the two tasks, where complex number arithmetic and backtracking algorithms for word squares are efficiently implemented. The code is written in an organised manner by the proper use of strict pragmas and well structured modular subroutines. Complex Squaresby Arne Sommer ![LinkedIn](linkedin.com) This approach to the Raku language shows how expressive it can be by using built-in Complex data type to implement calculations while simultaneously employing user-defined subset to adequately validate the unique string formats required by this challenge. In the case of the word squares task, this program uses backtrack recursive algorithm together with command line verification and clear formatting of its output. Perl Weekly Challenge: Week 395by Jaldhar H. Vyas ![LinkedIn](linkedin.com) Here, Jaldhar offers a dual-language simple rundown in Raku and Perl. In Raku, the Complex data type has an input normalisation and denormalisation part with respect to negative imaginary inputs, while Perl uses direct formula based parsing. In addition to that, a strong recursive depth-first search algorithm with prefix tracking is provided for solving the word squares problem in both programming languages. Complex Squaresby Jorg Sommrey This article illustrates stylish and solid implementations in Perl and J for multiplying complex numbers and creating word squares. The approaches make use of Regexp::Common for parsing and Math::Complex for calculations and regular recursive backtracking algorithm. The technical description of the methods is extensive and includes quite special formatting of input. The Weekly Challenge #395by Luboš Kolouch ![LinkedIn](linkedin.com) This entry presents an efficient dual language solution in Perl and Python, which comes with advanced regex parsing capability for the recognition of unusual complex number representations. In particular, the implementation of word squares is well optimised, thanks to the utilisation of a previously computed map of prefixes for smooth backtracking. Complex Squaresby Matthias Muth ![LinkedIn](linkedin.com) In his blog post, Matthias presents an incredibly neat and idiomatic Perl program. His solution for Task 1 uses Perl's map /-?\d+/g function to get all the numbers directly without any hassle, while Task 2 embodies an ingenious recursive backtracking strategy that follows up both rows and column prefixes at the same time. There was magic abroad in the air…by Packy Anderson ![LinkedIn](linkedin.com) This post will explore Challenge 395 in Raku, Perl, Python, and Elixir. It offers the reader a humorous reference to the song "A Nightingale Sang in Berkeley Square" in addition to clever parsing using regular expressions for working with complex numbers and a nice solution to the word squares problem. Complex wordsby Peter Campbell Smith In this article, an interesting exploration of how complex numbers are formatted mathematically is provided along with a smart and elegant Perl code which is used to process coefficients flexibly and multiply them. Words are Complexby Roger Bell West In this article, multiple languages provide an interesting perspective on how to solve the word squares problem. Roger describes how to implement a Perl string parser and construct the problem in a variety of languages, including Typst, where multiple solutions can be found by means of breadth-first search (BFS). The complex squareby Simon Green ![LinkedIn](linkedin.com) The article gives a clear and realistic description of the problem in both Python and Perl, using the built-in feature of complex numbers in Python and performing the arithmetic manually in Perl using regular expressions. --- Weekly collections NICEPERL's listsby Miguel Prz <a href="niceperl.blogspot.com">Great CPAN modules released last week</a>;<br><a href="niceperl.blogspot.com">MetaCPAN weekly report</a>. --- Events MCP - Model Context Protocol in Perl: From Web App to AI Tools - with Dave CrossOctober 21, 2026 Punk: Perl MVC, compiled at bootNovember 16, 2026 London Perl & Raku Workshop 2026November 21, 2026 YAPC::Tokyo 2026November 27, 2026 Everyday date and time handling in Perl with TNovember 29, 2026 German Perl/Raku Workshop 2027April 14-16, 2027 --- You joined the Perl Weekly to get weekly e-mails about the Perl programming language and related topics. Want to see more? See the archives of all the issues. Not yet subscribed to the newsletter? Join us free of charge! (C) Copyright Gabor Szabo The articles are copyright the respective authors.

    1 reaction
  3. The complex square Weekly Challenge 395 Each week Mohammad S. Anwar sends out The Weekly Challenge, a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. Unless otherwise stated, Copilot (and other AI tools) have NOT been used to generate the solution. It's a great way for us all to practice some coding. Challenge, My solutions Task 1: Complex Number You are given two complex numbers as string. Write a script to return the multiplication of the given complex numbers. Using the formula: (a + bi) x (c + di) = (ac - bd) + (ad + bc)i. My solution The last time I used complex numbers was high school. As a quick refresher, a complex number has two parts: 1) a real number and 2) an imaginary number (square root of -1). Python has builtin support for complex numbers. I have a function called to_complex which converts the provided value to a complex number. def to_complex(s: str) -> complex: if m := re.search(r"^(-?\d+)\+(\d+)i$", s): return complex(int(m.group(1)), int(m.group(2))) if m := re.search(r"^(-?\d+)\+\((-\d+)\)i$", s): return complex(int(m.group(1)), int(m.group(2))) raise ValueError("Unexpected input: %s", s) The main function converts the two strings into complex numbers, performs the multiplication, and returns the string in the expected format. def complex_number(num1: str, num2: str) -> str: c1 = to_complex(num1) c2 = to_complex(num2) result = c1 * c2 result_real = int(result.real) result_imag = int(result.imag) return ( f"{result_real}+{'('+str(result_imag)+')' if result_imag < 0 else result_imag}i" ) For the Perl solution, I went old school and performed the multiplication manually. sub to_complex($s) { if ( $s =~ /^(-?\d+)\+(\d+)i$/ ) { return $1, $2; } if ( $s =~ /^(-?\d+)\+\((-\d+)\)i$/ ) { return $1, $2; } die "Unexpected input: $s\n"; } sub main ( $num1, $num2 ) { my ( $r1, $i1 ) = to_complex($num1); my ( $r2, $i2 ) = to_complex($num2); my $result_real = $r1 * $r2 - $i1 * $i2; my $result_imag = $r1 * $i2 + $i1 * $r2; if ( $result_imag >= 0 ) { say "$result_real+${result_imag}i"; } else { say "$result_real+($result_imag)i"; } } Examples $ ./ch-1.py 1+1i 1+1i 0+2i $ ./ch-1.py "1+(-1)i" "1+(-1)i" 0+(-2)i $ ./ch-1.py 0+3i 0+4i -12+0i $ ./ch-1.py 3+4i "3+(-4)i" 25+0i $ ./ch-1.py "50+(-20)i" -10+30i 100+1700i Task 2: Word Squares You are given a list of equal lengths words. Write a script to arrange a set of words into a grid that reading across any row gives the exact same word as reading down its corresponding column My solution My solution for this task has a recursive function called find_word_squares, it takes two lists (array in Perl). The first list is called words which has the list of words provided by the user. The second parameter is words_so_far which is a list of words that make up the solution. I start by setting the words_so_far variable as an empty list on the first call. If a valid solution is found, I return that to the calling function. def find_word_squares( words: list[str], words_so_far: list[str] | None = None ) -> list[str] | None: if words_so_far is None: words_so_far = [] length = len(words[0]) if len(words_so_far) == length: return words_so_far The next step is to find possible next words. For this I generate the starts_with value with the letters the next word must start with. I also exclude any words already used. For each possible word (if any), I call the function again with an update words_so_far value. this_pos = len(words_so_far) starts_with = "".join(word[this_pos] for word in words_so_far) possible_next_words = [ word for word in words if word not in words_so_far and word.startswith(starts_with) ] for word in possible_next_words: result = find_word_squares(words, words_so_far + [word]) if result: return result If no solution is found, I return None. return None The main function checks that all words are the same length and calls the recursive function for the first time. def word_squares(words: list[str]) -> list[str] | None: # Check all words are the same length if any(len(word) != len(words[0]) for word in words): raise ValueError("All words must be the same length") # Call a recursive function to find the correct word order return find_word_squares(words) The Perl solution follows the same logic. Alternate solution An alternative option would be to calculate all permutations and see if it is valid. This is relatively inexpensive for the provided examples. There are only 120 permutations of 5 words. However if there were 17 words, that blows out to 355 trillion permutations. My solution still computes a large list quickly. $ time ./ch-2.py ABC CDE EFG GHI IJK KLM MNO OPQ QRS STU UVW WZY SUN USE NET SEE TEN ['SUN', 'USE', 'NET'] real 0m0.021s user 0m0.014s sys 0m0.006s Examples $ ./ch-2.py MA AM MY ME ['MA', 'AM'] $ ./ch-2.py SUN USE NET SEE TEN ['SUN', 'USE', 'NET'] $ ./ch-2.py BOAT TEAL AREA TSAR OGRE ['BOAT', 'OGRE', 'AREA', 'TEAL'] $ ./ch-2.py CARD AREA REAR DART ['CARD', 'AREA', 'REAR', 'DART'] $ ./ch-2.py HEART TREND EMBER RESIN ABUSE ['HEART', 'EMBER', 'ABUSE', 'RESIN', 'TREND']

  4. Weekly Challenge: The one about alternating Weekly Challenge 394 Each week Mohammad S. Anwar sends out The Weekly Challenge, a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. Unless otherwise stated, Copilot (and other AI tools) have NOT been used to generate the solution. It's a great way for us all to practice some coding. Challenge, My solutions Task 1: Alternate Case You are given a string containing an equal number of uppercase and lowercase English letters. Write a script to the minimum number of adjacent character swaps needed to turn the given string into an alternate case string. My solution I'm pretty sure I've overengineered this solution, given that it is task one. For this I start with two constants called UCL and LCL which is a set of upper case letters and lower case letters respectively. import string UCL = set(string.ascii_uppercase) LCL = set(string.ascii_lowercase) I then have a function is_alt_case. It determines if the string is alternating between upper and lower case letters. If it is, it will return None (-1 for the Perl solution). If it finds a letter with incorrect case, it will find the position of the next letter in the correct case and returns one less than that position. This represents the letters that will be swapped. def is_alt_case(s: str, upper_first: bool) -> int|None: for pos, letter in enumerate(s): next_letters = UCL if (upper_first + pos) % 2 else LCL if letter in next_letters: continue for i in range(pos+ 1, len(s)): if s[i] in next_letters: return i-1 return None As strings are immutable in Python, I have function called swap_letters. Given a string s and an integer pos, it will swap the letters in position pos and pos+1. def swap_letters(s: str, pos: int) -> str: return s[:pos] + s[pos+1] + s[pos] + s[pos+2:] The main function starts by checking that the strings is valid, specifically it contains only letters, has an even number of letters and half of them are upper case. def alt_case(input_string: str) -> int: half_length = len(input_string) // 2 if len(input_string) % 2: raise ValueError("String must have an even number of characters") if not re.search("^[a-z]+$", input_string, flags=re.I): raise ValueError("The word contain non-letter characters") if sum(1 for letter in input_string if letter in UCL) != half_length: raise ValueError( "Letter must contain the same number of upper and lower case letters" ) As I don't know if the string should start with an upper case or lower case letter, I try both and return the one with the minimum number of moves. I have a loop that calls is_alt_case until it returns None (meaning the string is correct) counting moves for each move made. move_list = [] for upper_first in {True, False}: s = input_string moves = 0 while (next_swap_pos := is_alt_case(s, upper_first)) is not None: s = swap_letters(s, next_swap_pos) moves += 1 move_list.append(moves) return min(move_list) Examples $ ./ch-1.py aAbB 0 $ ./ch-1.py AAbb 1 $ ./ch-1.py AAAbbb 3 $ ./ch-1.py aABb 1 $ ./ch-1.py bBBAaa 2 Task 2: Alternating Vowels Consonants You are given three strings containing English alphabetic characters. Find all the longest contiguous substrings common to all three strings that strictly alternate between vowels and consonants. My solution For this challenge, I define a function called is_alt_vc. It checks if the substring alternates between vowels and consonants. For the first letter, it sets vowel_next to True or False depending on the type of it. It then alternates this variable for each subsequent letter. def is_alt_vc(substr: str) -> bool: # Start with the type of the fist letter vowel_next = substr.lower()[0] in VOWELS for letter in substr.lower(): if vowel_next ^ (letter in VOWELS): # The letter is the wrong type return False # The next letter needs to be the opposite vowel_next = not(vowel_next) # The word alternates between vowels and consonants return True The main function starts by checking that all the supplied words only contain letters of the English alphabet. def alt_vc(words: list[str]) -> list[str]: if not all(re.search('^[a-z]+$', word, flags=re.I) for word in words): raise ValueError("Some words contain non-letters") I then find the shortest_word (the first if there is more than one of the same length) and the length of that word. The maximum possible solution is this length. shortest_word = sorted(words, key=len)[0] min_length = len(shortest_word) I then have a double loop. The outer loop is called length and starts with min_length and decreases to 1. The inner loop is called start representing the starting position of the substr, the value is 0 up to the min_length - length. I then generate the substring, and check if it appears in all words and alternates between vowels and consonants. If one or more substrings of a specific length is found, I return all the substrings found. If the loops are exhausted, I return an empty list (array in Perl). result = [] for length in range(min_length, 0, -1): for start in range(min_length-length+1): substr = shortest_word[start:start+length] if all(substr in word for word in words) and is_alt_vc(substr): result.append(substr) if result: return sorted(result) return [] Examples $ ./ch-2.py relocate delocate allocate ("locate") $ ./ch-2.py apple banana cherry () $ ./ch-2.py navigate cavity gravity ("avi") $ ./ch-2.py pedalgia pedalboard pedantic ("peda") $ ./ch-2.py schoolmaster schoolhouse schooling ("ho", "ol")

Latest stargazers

The last 10 distinct accounts we observed this year.

Most active participants

PR, issue, comment & review events in the past year.

Packages

8
PackageVersionDownloads · 30dTrend · 30d
———
———
———
———
———
———
———
———

README badges

Embed a badge in your README or website.

Live mentions · last 30 days
manwar/perlweeklychallenge-club mentions in the last 30 days