# Blog

• PWC 047 › Roman Calculator
The first challenge this week tasks us with evaluating arithmetic operations using Roman numerals. The description seems to indicate that only one operation will be given (for example, II + IV), but I have elected to support arbitrary arithmetic expressions. First, I needed a way to convert to and from Roman and Arabic numerals. I … Read more
• PWC 047 › Gapful Numbers
Task 2 this week has us print the first 20 "gapful numbers," as described by OEIS sequence A108343. Gapful numbers are numbers greater than 99 that are evenly divisible by their first and last digits combined. For example, 132 is a gapful number because 132 ÷ 12 = 11. This is certainly the easier of … Read more
• PWC 046 › Cryptic Message
Challenge #1 this week is the following: The communication system of an office is broken and message received are not completely reliable. To send message Hello, it ended up sending these following: H x l 4 ! c e – l o z e 6 l g H W l v R q 9 m # … Read more
• PWC 046 › Is the Room Open? (500 Doors)
The second of the challenges this week poses the following question (paraphrased): Suppose we have 500 doors, and 500 employees. The first employee opens all the doors. The second employee closes every 2nd door (doors 2, 4, 6, … 500). The third employee closes every third door if it is open, or opens it if … Read more
• Quine
Challenge #2 this week asks for "a script that dumps its own source code". This is almost a quine, although Mohammad did not name it as such. Specifically, we are given the constraint that perl ch-2.pl | diff – ch-2.pl must return nothing. What's a Quine? A quine, otherwise known as a self-replicating program, is … Read more
• Square Secret Code
Task #1 this week is a simple cipher, described as follows: The square secret code mechanism first removes any space from the original message. Then it lays down the message in a row of 8 columns. The coded message is then obtained by reading down the columns going left to right. Given "The quick brown … Read more
• Make it $200 For challenge #2 this week, the task is to start with$1, and by either adding $1 or doubling the amount, reach$200 in the smallest possible number of steps. "Greedy never works" In a 75-minute lecture some decades ago, my Advanced Algorithms professor said, over and over, "greedy never works," while all the while … Read more
• Only 100, please
Challenge #1 this week is as follows: You are given a string “123456789”. Write a script that would insert ”+” or ”-” in between digits so that when you evaluate, the result should be 100. I am going to add the additional constraint that we want all possible solutions, because that is a much stronger statement, and not that difficult to … Read more
• Self-descriptive Numbers
Challenge #2 this week (43) is to generate Self-descriptive Numbers in arbitrary bases. A self-descriptive number, as described by Wikipedia, is an integer m that in a given base b is b digits long in which each digit d at position n (the most significant digit being at position 0 and the least significant at position b – 1) counts how many instances of digit n are … Read more
• Olympic Rings
Challenge #1 this week (43) is a number puzzle. In short, the task is to fill in the numbers 1, 2, 3, 4, and 6 into the spaces within the intersecting Olympic rings, so that the numbers in each ring sum to 11. Some of the spaces are already filled in (given). Here is the … Read more
• Balanced Parentheses
The second challenge this week is another old chestnut: Write a script to generate a string with random number of ( and ) brackets. Then make the script validate the string if it has balanced brackets. The question has two parts: Generate strings with random brackets There are many ways to go about this task. However, I'm opting to … Read more
• Octal Representation
Challenge 1 this week is an easy one: Write a script to print decimal number 0 to 50 in [the] Octal Number System. Perl and Raku We can solve this with the following polyglot (runs in both languages at once): printf "Decimal %2d = Octal %2o\n", $_,$_ for 0..50; Still, in Raku, we can do … Read more
• Leonardo Numbers
Happy new year! We are on Week 41, and this is Challenge #2. The Leonardo Numbers (A001595) are a simple recursively defined sequence: $$L(n) = \begin{cases}1 & \text{if } n \lt 2 \\1 + L(n – 1) + L(n – 2) & \text{if } n \geq 2\end{cases}$$ The sequence starts: 1, 1, 3, 5, 9, … Read more
• Attractive Numbers
This week, Mohammad asks us to output a list of all Attractive Numbers between 1 and 50. Attractive numbers, as described by the Online Encyclopedia of Integer Sequences (OEIS) are: Numbers with a prime number of prime divisors (counted with multiplicity) OEIS Sequence A063989 The first numbers are 4, 6, 8, 9, 10, 12, 14, … Read more
• Zip6
The zip6 function has long been a staple of the List::MoreUtils CPAN module. The Week 40 challenge #1 describes it very well. But even more succinctly: zip6 takes an array of arrays (AoA) and returns another AoA of all the 1st elements, then the 2nd, and so on. It's not a difficult algorithm by any … Read more
• Reverse Polish Notation
This is my first blog post regarding the Perl Weekly Challenge tirelessly maintained by Mohammad Anwar. Although I've been doing the challenge for a while now, I haven't maintained my blog for years. Let's change that! This week's challenge #2 from the Perl Weekly Challenge is a computer science classic: create a Reverse Polish Notation … Read more