Perl Weekly Challenge # 18: Priority Queues and Binary Heaps In Perl 6

In this previous blog post, I provided some answers to the Week 18 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

However, I omitted the Perl 6 solution to the priority queues part of the challenge, because I wanted to use a binary heap to solve it, and this required too many explanations: the blog post was just getting too long. So this post will complete the previous post and look into binary heaps in Perl 6.

Spoiler Alert: This weekly challenge deadline is due in several days from now (July 28, 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.

This part of the challenge goes like this:

Six slices of pie

The first task of the 15th Weekly Challenge was to find the optimal position in the line for dessert.

This is a reformulation of the old conundrum of creating buggy whips or cowboy movies or physical book stores or carbon-based energy sources: when is the best time to opt in for an ever-increasing slice of an ever-diminishing pie?

In this task, the pie is big enough for 100 people, but the first person in line gets a slice equivalent to only 1% of it. The second person gets 2% of what’s left, the third gets 3% of what remains after that, et cetera, et cetera, until the one-hundredth person receives 100% of whatever crumbs are left after the preceding ninety-nine have taken their share. In other words, we’re “Making Apple-pie Great Again!”

Windows and Perl

Doing development work on Windows is becoming easier and better all the time. However, it's still somewhat cumbersome to do development work ON Windows, FOR Windows.

Strawberry
Luckily for us Perl developers, the team making Strawberry Perl have done an excellent job for quite some time. Their efforts make installing and using Perl on our Windows environments (PowerShell or cmd.exe) dead simple.

BerryBrew
That being said, something we find ourselves doing more and more frequently when doing development work on Linux is switching between versions of Perl quickly and easily. This has been available to us with BerryBrew for some time.

What Have I Done?! (PSPerl)
What I've started work on recently is a PowerShell version of a Perl environment switcher, called PSPerl. On linux we have perlbrew and plenv, why not have another option on Windows?

Given that it's written entirely in PowerShell v5+, it should be easy to update, maintain, and add new features - or even implement your own features. Give it a try. Find problems. Help me fix them.

The Perl Community - a mixed bag of sometimes intollerance and sometimes fantastic help

I've had occassions to post a post like this a number of times in the past over a lot of years but I've resisted until now. I have little experience of other programming languages in forums/IRC/blogs etc recently because these days I've largely written Perl and PL/SQL but in the past before the WWW was prevelant I programmed in Fortran, Pascal, C, Macro 32, VMS, Z80, 8086, 6502 etc before I volunteered to port a large code base from VMS to UNIX.

Perl Weekly Challenge # 18: Longest Common Substrings, Priority Queues, and a Functional Object System

These are some answers to the Week 18 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in several days from now (July 28, 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: Longest Common Substrings

Write a script that takes 2 or more strings as command line parameters and print the longest common substring. For example, the longest common substring of the strings “ABABC”, “BABCA” and “ABCBA” is string “ABC” of length 3. Other common substrings are “A”, “AB”, “B”, “BA”, “BC” and “C”. Please check this wiki page for details.

Swiss Perl Workshop 2019 - Less Than One Month

It's less than one month until this year's Swiss Perl Workshop. Perhaps you would like to join us and maybe even submit a talk? It can be anything Perl, anything slightly related to Perl, or just plain old anything that you've found interesting in technology recently that isn't Perl at all.

This year's workshop wouldn't be possible without the sponsors, so we thought we should tell you a little bit about them:


Oetiker + Partner AG
OETIKER+PARTNER is a Swiss system management and software development company. Employees from O+P are involved in many Open Source Software projects.
Humanstate
Founded in 2001, Humanstate is a private technology services group that provides businesses and organisations in various vertical markets with state-of-the-art web-based software applications integrated with on-demand payment processing. Humanstate owns and manages a global transactional platform that forms the core of all its solutions.
infomaniak

The Time::Local Trap

The localtime and gmtime built-in functions are interfaces to the POSIX functions for turning a Unix epoch timestamp into date-time components in either UTC or the system local time. When you want to go the other way, there's Time::Local.

Well, almost.

The localtime and gmtime functions have two quirks as compared to the date-time components humans might expect. The value it returns for the month is 0-indexed, ostensibly so that it can be used directly in a 0-indexed array of 12 month names, and the value it returns for the year is the number of years since the year 1900.

Perl Weekly Challenge 017: Ackermann Function and URL Parsing

Ackermann Function

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

I know that Perl6 supports multisubs, but when I see a function definition of this kind, I always think Erlang, where you get pattern matching and multisubs by default. Here’s how it looks:

-module(ackermann).
-export([ackermann/2]).

ackermann(0, N) ->
    N + 1;
ackermann(M, 0) ->
    ackermann(M - 1, 1);
ackermann(M, N) ->
    ackermann(M - 1, ackermann(M, N - 1)).

Perl solution is a bit less straightforward.

Perl jam @Booking.com ML center

I just spotted this on Twitter.

Booking.com are hosting a "Perl Jam" event on Monday 29 July 2019, 6:00pm
at Azrieli Sarona Tower, Tel Aviv-Yafo Israel.

There are three speakers- so it looks like a great way to spend an evening rather than a full on conference.

Registration at: https://bookingcareerseventstelaviv.com/perl-meetup-booking-com-ml-center

Up, up and Away!

This week's perl weekly challenge was a lot of fun. First of all, challenge number 2 was a breeze. The challenge was to parse and print the components of a URL. That was easy...

Perl Weekly Challenge && Damian Conway

I have been a big fan of Damian Conway ever since I bought his book "Perl Best Practices". With the recent regular blog by him about various tasks from the Perl Weekly Challenge showed us really interesting aspects of the task. The one he blogged, Vigenère vs Vigenère last was really special about Vigenere Cipher. I must admit I didn't know half of what he shared in the blog. I wonder how many knew the Vigenere Cipher wasn't invented by Vigenere.

I think, I owe him a drink next time I meet, as per the English tradition. However, being a practicing Muslim, I can't offer drink, instead I would offer box of chocolates.

In the mean time, I am going to reserve space for him in the weekly blog by name "Damian Corner" where we would talk about his blog.

What else happening these days?

I try to keep myself busy during the week by writing short blogs. In the weekly series "Meet The Champion", we recently spoke to Adam Russell, the winner of Perl Weekly Challenge - 016.

I also blogged about the optional API task which we introduced recently. Check out how Neil Bowers took it to another level. Perl Weekly Challenge - Optional API Task.

Enjoy !!!

TPF: Perl deserves better. Please do better.

A recent Standards of Conduct incident[1] regarding The Perl Conference 2019 (TPC) has been deeply divisive within the Perl Community, and handled so poorly that a "clarification" has since been issued[2].

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.

Using generate_series and daterange for fun and profit

Read it here!

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

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.

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;

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.