Perl Weekly Challenge # 17: Ackermann Function and Parsing URLs
These are some answers to the Week 17 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
Spoiler Alert: This weekly challenge deadline is due in several days from now (July 21, 2019). This blog post offers some solutions to this challenge, please don't read on if you intend to complete the challenge on your own.
Challenge # 1: Ackermann Function
The common Ackermann function, named after Wilhelm Ackermann, is defined recursively as follows:
A(m, n) = n + 1 if m = 0
A(m, n) = A(m - 1, 1) if m > 0 and n = 0
A(m, n) = A(m - 1, A(m, n - 1)) if m > 0 and n > 0
The function grows very rapidly even for relatively small input values, so you may not want to try to compute it for input values such as 5 and 6. You probably don't even want to try it with the first input parameter (m
) larger than 3. It also does a very large number of recursive calls, so that it will tend to be very slow.
Super 30 - Anand Kumar
Some of you, who know me personally, knows my background and how I managed to reached London in 2000. For others, I belong to a state called Bihar, in India. I was born and raised in the city of Jamshedpur. A city built by Tata. Who Tata? They are well respected Industrial group.
I still remember, outside of Bihar, people don't treat us well if they know you are from Bihar. I can tell you from my own experience when I moved to Mumbai (Bombay) in the year 1997. Because of this, people from Bihar don't disclose their identity. Recently some parts of Bihar got separated and created a new state "Jharkhand". In the process, Jamshedpur now belongs to newly created state Jharkhand. However, I still feel my roots belong to Bihar. It gives me immense pride when I hear nice thing about Bihar.
Using generate_series and daterange for fun and profit
P.S.: As it seems that the ironman perl blog aggregator is down, I (ab)use blogs.perl.org to alert you of my new posts..
BackupPC 4.3.1 release
BackupPC is a high-performance, enterprise-grade system for backing up Linux, WinXX, and MacOS PCs and laptops to a server's disk. BackupPC is highly configurable and easy to install and maintain.
Given the ever decreasing cost of disks and raid systems, it is now practical and cost effective to backup a large number of machines onto a server's local disk or network storage. This is what BackupPC does. For some sites, this might be the complete backup solution. For other sites, additional permanent archives could be created by periodically backing up the server to tape. A variety of Open Source systems are available for doing backup to tape.
BackupPC is written in Perl and extracts backup data via SMB (using Samba), rsync, or tar over ssh/rsh/nfs. It is robust, reliable, well documented and freely available as Open Source on GitHub.
This release contains several bug fixes.
Find out more at https://github.com/backuppc/backuppc/releases/tag/4.3.1
The Perl Conference in Riga
Short version: I'll be there.
Long version: people have been asking me why I've not been as visible in the Perl community as I used to be (including at least one person asking if I was still involved in Perl). Well, that's a long story.
Vigenère vs Vigenère
The second task of the 15th Weekly Challenge was to implement
an encoder and a decoder for the Vigenère Cipher. But that’s a
little more complicated than it seems, because the cipher that's named
after Blaise de Vigenère wasn’t actually invented by him, and the cipher
that Vigenère actually invented isn’t named after him.
So should we implement the Vigenère Cipher...or Vigenère’s cipher?
Why not both!
The Vigenère Cipher was devised by Giovan Battista Bellaso in 1553,
and then misattributed to Vigenère about three hundred years later.
It uses a tabula rēcta to translate from a message text to a ciphertext,
and back again.
Given an user-provided key (e.g. "BELLASO"
), we encipher a message
(e.g. "VIGENEREDIDNOTINVENTTHIS"
) by matching up respective letters of the
key and message, then using them as two indices to look up the corresponding
cipher character in the appropriate column and row of the tabula rēcta.
And if the key is shorter than the message, we just recycle the key
as many times as necessary.
For example:
Perl Weekly Challenge 016: Pythagoras Pie Puzzle and Bitcoin Address Validation
Pythagoras Pie Puzzle
At a party a pie is to be shared by 100 guest. The first guest gets 1% of the pie, the second guest gets 2% of the remaining pie, the third gets 3% of the remaining pie, the fourth gets 4% and so on. Write a script that figures out which guest gets the largest piece of pie.
I started with a straightforward implementation of the specification. Start with the pie of size 1; in each step, find out the size of the corresponding guest’s part, remember it if it’s largest one so far, and decrease the size of the pie.
Pizza Party for 100
Hi all, this is my first blog post! Yay!
Now that that's out of the way, I'd just like to go over my solution for this week's Perl weekly challenge.
The first challenge was to divide a pie between 100 people, in a manner where the first guest gets 1/100 (i.e. 1%) of the pie, and the second gets 2/100 (i.e. 2%) of what remained, etc etc. The question is, who got the biggest piece of pie.
If I were better at math, I would prove that the answer is the square root of the amount of guests, because that does seem to be the case. Since I'm not, I solved it procedurally, as follows.
We set up our guests. We allow for the user to pass in a value on the command line, to check values other than 100, but default to 100:
use v5.22; #that's my perl
my $guests = shift // 100;
Perl Weekly Challenge # 16: Bitcoin Addresses
In this post dated July 8, I provided solutions to the first challenge of Week 16 of the Perl Weekly Challenge organized by Mohammad S. Anwar. At the time, I admitted that I was having trouble understanding the requirement for the second challenge. After quite a bit of googling, I can finally provide some answers to the second challenge of Week 16.
I should acknowledge that I spent far more time on this than I would wish to admit. Far more time than I ever did on any of the previous challenges.
Validation of Bitcoin Addresses
Perl Weekly Challenge #016
Task #1: Pythagoras Pie Puzzle
This puzzle’s connection with Pythagoras is tenuous indeed: it originally appeared in the Dutch magazine Pythagoras (see here and here)! But the puzzle is interesting. Of course, the real challenge is to work out the answer mathematically, but for those of us who are mathematically declined a Perl script is the way to go.
The first draft of my solution was tied to the 100 guests specified in the puzzle statement, but it’s easy to extend the puzzle to allow any (positive integer) number of guests. So I include the number of guests as a constant $GUESTS
and the central calculation becomes:
$piece = ($guest / $GUESTS) * $pie;
where $guest
is any number in the series 1 .. $GUESTS
and $pie
is the fraction of original pie remaining at this point in the distribution.
Perl 5 solution
For my own interest I added code to display the size of each guest’s piece of pie. This code can be omitted from compilation by setting DEBUG
to a false value.
File ch-1.pl
RPerl at the Perl Conference in Pittsburgh - Day 3
Howdy!
We're back for the final day of the Perl Conference. Wendy and Liz were very much missed this year, but we had enough Perl items to set up a booth, with the help of Ruth Holloway and Peter Sargent. The table was full of buttons, stickers, tuits, and other info from Perl Careers.
On this final day we attended the traditional Q&A with Larry Wall. People were able to send their questions via Twitter, and I asked Larry who his favorite musical composer is.
I'm not a technical person, but I am a violinist, which gives me something in common with Larry Wall! Pretty cool, right? Anyway, Larry's answer was Gustav Mahler. Very good answer Larry, I myself am a Mahler enthusiast. What I remember from this Q&A session is Larry's call for peace and respect. The Perl community has a lot of great people, very different from one another. The things we have in common should always surpass our differences.
Next stable DBD::SQLite will be released in the mid-August
DBD::SQLite 1.63_05 (with SQLite 3.29.0) is a release candidate for the next stable DBD::SQLite. There are no big changes, maybe except for two new db_config options to disallow double-quoted string literals.
use DBD::SQLite::Constants qw/:database_connection_configuration_options/;
$dbh->sqlite_db_config( SQLITE_DBCONFIG_DQS_DML, 1 );
$dbh->do('INSERT INTO foo VALUES (1, "text")'); # Now this is an error
I'll wait for about a month as always, and release 1.64 in the middle of August (that means, after PerlCon) if there's no blocker nor request to wait for more. Thank you for your patience.
Infinite work is less work
The first task of last week's Weekly Challenge was to print the
first ten strong and weak primes. A prime pn is "strong" if it's larger
than the average of its two neighbouring primes (i.e. pn > (pn-1+pn+1)/2).
A prime is "weak" if it's smaller than the average of its two neighbours.
Of course, this challenge would be trivial if we happened to have a list
of all the prime numbers. Then we'd just filter out the first ten that
are strong, and the first ten that are weak. In fact, it would be even
easier if we happened to have a list of all the strong primes, and a
list of all the weak ones. Then we'd just print the first ten of each.
But there are an infinite number of primes and of weak primes (and
possibly of strong primes too, though that's still only conjectured),
so building a complete list of the various subspecies of primes
is impractical in most programming languages.
Meet The Champion - Joelle Maslak
As a part of weekly series "Meet The Champion", we are talking to the last week winner Joelle Maslak.
# Perl Weekly Challenge # 16: Pythagoras Pie
These are some answers to the Week 16 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
Spoiler Alert: This weekly challenge deadline is due in several days from now (July 14, 2019). This blog post offers some solutions to this challenge, please don't read on if you intend to complete the challenge on your own.
Challenge # 1: Pythagoras Pie
At a party a pie is to be shared by 100 guest. The first guest gets 1% of the pie, the second guest gets 2% of the remaining pie, the third gets 3% of the remaining pie, the fourth gets 4% and so on. * Write a script that figures out which guest gets the largest piece of pie. (Challenge proposed by Jo Christian Oterhals)*
RPerl at the Perl Conference in Pittsburgh - Day 2
Day 2 of the Perl Conference, and I am now a seasoned volunteer! I know all about HDMI recorders and cameras - well, almost…
This second day saw the very first meeting of the Perl Mongeresses, a Birds-Of-a-Feather for women in the Perl community. This year’s Perl Conference was notable for the highest known attendance of women to The Perl Conference ever! By highest, I mean… about 15 ladies total. Yes, there’s still work to do. This meeting was the opportunity to discuss issues that women are facing in the programming world.
Thank you, Ruth Holloway, for the Perl Mongeress initiative! I’m looking forward to the second edition next year. If some of my female readers plan to attend the PerlCon in Riga next month, you still have time to add one to the BoFs...
Leaving irc.perl.org
This article just popped up on Twitter. Whilst I mostly idle on irc.perl.org (say hello in #australia) I have no idea who runs or ran it. Whilst I noticed that there seems to be several servers (at lease one of which being apparently provided by shadowcat systems). I had assumed this was largely just people keen to run their own local instance - irc serving not requiring much in terms of system resources.
I guess my reaction to the article is to feel some contribution to the "use but not contribute", although i'm not even an admin in a channel. IRC across the board is waning in the face of CPU and RAM hungry chat softwares.
It seems that if you can make chat software that requires you to upgrade your CPU and RAM you've got yourself a hot start up, even if you're largely replicating features available in irc and email lists.
With other efforts to reinvigorate this blog site, and other key perl websites, perhaps its time to include IRC (or others) in a strategic plan?
Perl Weekly Challenge - Meet The Champion
We have started weekly series "Meet The Champion" where we would speak to the winner of the "Perl Weekly Challenge". So far we have had two winners. Please checkout the interviews with the champions.
- Perl Weekly Challenge - 013: Laurent Rosenfeld
- Perl Weekly Challenge - 014: Jaldhar H. Vyas
Please let us know if we missed anything.
Functional Programming in Perl: Strong and Weak Primes (Perl Weekly Challenge)
In this other blog post, I provided some answers to Week 15 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
Here, I want to use the opportunity of this challenge to illustrate once more some possibilities of functional programming in Perl (both Perl 5 and Perl 6) using the example of the first challenge of this week. I have already covered some aspects of functional programming in Perl in a post related to Weekly Challenge 9.
About blogs.perl.org
blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.