Perl Weekly Challenge 286: Order Game

These are some answers to the Week 286, Task 2, of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few days from now (on September 15, 2024, at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 2: Order Game

You are given an array of integers, @ints, whose length is a power of 2.

Write a script to play the order game (min and max) and return the last element.

Example 1

This week in PSC (157) | 2024-08-23

Just Aristotle and Philippe this time (Graham chipped in on IRC):

  • we discussed the apostrophe situation: we will watch 5.41.3 break CPAN, and then evaluate the actual fallout. We like the idea of guarding this with a feature (which might need to be split in two, for the string interpolation case)
  • we had a long discussion about backwards compatibility and use VERSION. Should "did you use VERSION?" become the new "did you use strict and warnings?"

[P5P posting of this summary]

Second Batch of LPW 2024 Talks Accepted

Yep, that's right - the second half dozen talks have been accepted for this year's London Perl and Raku Workshop. This puts our schedule at approximately 80% full, so if you are thinking about talking at the workshop then submit your proposal now!

The CFP will be closed at the end of September to give speakers sufficient time to finish their presentations and to allow the schedule to be created. We encourage all attendees to mark talks they are interested in as that will inform some of the schedule choices.

If you aren't thinking about talking then have a think about what you've been doing in the Perl and/or Raku space the last five years, or even just the general IT and development space. Perhaps there's something interesting you can talk about? If you don't feel it's a full fat talk then submit a lightning talk instead.

The London Perl and Raku Workshop will take place on 26th Oct 2024. Thanks to this year's sponsors, without whom LPW would not happen:

If you would like to sponsor LPW then please have a look at the options here: https://act.yapc.eu/lpw2024/sponsoring.html

Updated, curated, Perl module TiddlyWiki

Download the Perl TiddlyWiki

Read about TiddlyWIkis

Cheers

Perl Weekly Challenge 286: Self Spammer

These are some answers to the Week 286, Task 1, of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few days from now (on September 15, 2024, at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 1: Self Spammer

Write a program which outputs one word of its own script / source code at random. A word is anything between whitespace, including symbols.

Example 1

If the source code contains a line such as: 'open my $fh, "<", "ch-1.pl" or die;'
then the program would output each of the words { open, my, $fh,, "<",, "ch-1.pl", or, die; }
(along with other words in the source) with some positive probability.

Example 2

Technically 'print(" hello ");' is *not* an example program, because it does not
assign positive probability to the other two words in the script.
It will never display print(" or ");

Example 3

How to use perl v5.40's boolean builtins in Mojo::Pg queries

Perl v5.40 introduced native true and false keywords. Unfortunately not all CPAN modules are ready to use them. One of those not yet ready is Mojo::Pg.

Normally you'd want to pass booleans to your queries as just 1's and 0's. However, since Mojo::JSON's true & false stringify to 1 and 0, my 5.38-using codebase is full of Mojo::Pg queries with Mojo::JSON's true and false as arguments.

This is a problem if I want to upgrade the perl interpreter of that project to Perl v5.40, because if I write "use v5.40;" in the file that contains those boolean keywords, Perl's builtin booleans will be used instead, which don't stringify to 1 and 0, but to 1 and the empty string, which can't be used by DBD::Pg in boolean fields and makes DBD::Pg throw an exception.

The solution I found was to subclass Mojo::Pg::Database, and wrap the query method, so that if Perl's builtin booleans are found, they are replaced in the query with native Pg booleans.

The source of the module and a lot more information can be found in my blogpost, here.

Caching & Memoization with state variables

Chapter 3 of Higher Order Perl describes various approaches to memoization of an expensive function: private cache and the Memoize module. The book was written in 2005 (Perl was at version 5.8 back then) , so it does not include another way for function caching that is now available : caching through state variables (introduced in Perl 5.10). The Fibonacci example considered in HOP also requires the ability to initialize state hash variables (available since Perl 5.28). The code below contrasts the implementation with a state variable v.s. the memoize module:

What's new in Perl v5.40?

Here I share my personal favourite core enhancements in Perl v5.40.

https://theweeklychallenge.org/blog/what-is-new-in-perl

Perl Weekly Challenge 285: Making Change

These are some answers to the Week 285, Task 2, of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few days from now (on September 8, 2024, at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 2: Making Change

Compute the number of ways to make change for given amount in cents. By using the coins e.g. Penny, Nickel, Dime, Quarter and Half-dollar, in how many distinct ways can the total value equal to the given amount? Order of coin selection does not matter.

A penny (P) is equal to 1 cent.
A nickel (N) is equal to 5 cents.
A dime (D) is equal to 10 cents.
A quarter (Q) is equal to 25 cents.
A half-dollar (HD) is equal to 50 cents.

This week in PSC (152) | 2024-06-20

Just Graham and Philippe this time.

We talked about HTTPS in core, and some ideas about it, while the CPAN Security Group is preparing some proposals. Today was the deadline for releasing 5.41.1, but we don’t have volunteers yet, so Graham said he would do it sometime soon.

We also noted that we’ll need some volunteers for the next 10 or so development releases.

Neuigkeiten: OTOBO 11 Veröffentlicht

Wir freuen uns, die Veröffentlichung von OTOBO 11 bekannt zu geben! Die neueste Version der beliebten Open-Source-Ticketsystem-Software bringt zahlreiche Verbesserungen und neue Funktionen mit sich. Erfahren Sie mehr über die neuen Features und Änderungen auf OTOBO

Making time to waste.

Over the years that I have existed in four dimensions, I have come to accept that time is not a linear concept heading inexorably in one direction at a uniform rate. It didn't take an Einstein or Hawking to convince me either. Time is as malleable as the distortions applied by our consciousness, or imposed by those around us. Consider my youngest daughter's essay due to be handed in on Tuesday, a task assigned 4 months earlier. At 4,000 words, it represented roughly 6 words an hour allowing for eating, sleeping, work, weekend fun, and other essential time-devouring activities. Yet the "I have got plennnnty of time, chill, dad!" of a few months ago, has now turned into cries of despair, as she has to do an all nighter at her desk instead of being at some selfie-rich event critical to her mental well-being and social standing.

Perl Weekly Challenge 285: No Connection

These are some answers to the Week 285, Task 1, of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few days from now (on September 8, 2024, at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 1: No Connection

You are given a list of routes, @routes.

Write a script to find the destination with no further outgoing connection.

Example 1

Input: @routes = (["B","C"], ["D","B"], ["C","A"])
Output: "A"

"D" -> "B" -> "C" -> "A".
"B" -> "C" -> "A".
"C" -> "A".
"A".

This week in PSC (151) | 2024-06-13

Graham and Philippe met briefly today.

Now that Perl 5.40 is out, and the nomination process for the next PSC is underway, there wasn’t much to discuss, so we cut the meeting short.

Equalise an Array

The Weekly Challenge 270/2

In the week 270, the second task was really interesting and difficult. Here’s a slightly reformulated version:

We’re given an array of positive integers @ints and two additional integers, $x and $y. We can apply any sequence of the following two operations: 1. Increment one element of @ints. 2. Increment two elements of @ints. The cost of each application of operation 1 is $x, the cost of operation 2 is $y. What’s the minimal cost of a sequence of operations that makes all the elements of @ints equal?

Why do I say it was difficult? I compared all the Perl and Raku solutions I could find in the GitHub repository and none of them gave the same results as mine. It took me several days to find an algorithm that would answer the tricky inputs I generated with a pen and paper, and one more day to optimise it to find the solutions in a reasonable time.

Perl Toolchain Summit 2024 in Lisbon

Last year at the Perl Toolchain Summit (PTS) in Lyon, I left three draft pull requests: one about the class declaration introduced in Perl 5.37, one about the PAUSE on docker, and one about multifactor authentication. I wanted to brush them up and ask Andreas König to merge some, but which should I prioritize this year?

Perl Weekly Challenge 284: Relative Sort

These are some answers to the Week 284, Task 2, of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few days from now (on September 1, 2024, at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 2: Relative Sort

You are given two list of integers, @list1 and @list2. The elements in the @list2 are distinct and also in the @list1.

Write a script to sort the elements in the @list1 such that the relative order of items in @list1 is same as in the @list2. Elements that is missing in @list2 should be placed at the end of @list1 in ascending order.

Example 1

Input: @list1 = (2, 3, 9, 3, 1, 4, 6, 7, 2, 8, 5)
       @list2 = (2, 1, 4, 3, 5, 6)
Ouput: (2, 2, 1, 4, 3, 3, 5, 6, 7, 8, 9)

Example 2

This week in PSC (156) | 2024-08-15

Just Graham and Aristotle this time.

  • Discussed some patches to include in a perl 5.38 or 5.40 point release.
  • We will be watching the fallout from the removal of apostrophe as package separator.
  • Discussed what could be done for lexical method calls.

[P5P posting of this summary]

MariaDB 10 and SQL::Translator::Producer

Following up on my previous post (MariaDB 10 and Perl DBIx::Class::Schema::Loader), I wanted to try the 'deploy' feature to create database tables from Schema/Result classes.

I was surprised that I could not create a table in the database when a timestamp field had a default of current_time(). The problem was that the generated CREATE TABLE entry placed quotes around 'current_timestamp()' causing an error and rejected entry.

As mentioned in a previous post, I had created file SQL/Translator/Producer/MariDB.pm as part of the effort to get MariaDB 10 clients to work correctly with DBIx::Class::Schema::Loader. Initially it was a clone of the MySQL.pm file with name substitutions. To correct the current_timestamp problem I added a search/replace in the existing create_field subroutine in the MariaDB.pm file to remove the quotes.

Confirming The LPW 2024 Venue & Date

We're happy to confirm the venue and date of this year's London Perl & Raku Workshop.

When: Saturday 26th October 2024
Where: The Trampery, 239 Old Street, London EC1V 9EY

This year's workshop will be held at The Trampery, at Old Street. A dedicated modern event space in central London. We have hired both The Ballroom and The Library; allowing us to run a main track for up to 160 attendees, and second smaller track for up to 35 attendees.

The Trampery in Old Street is located a two minute walk from the Northern Line's Old Street tube station in central London. The Northern Line has stops at most of the major train stations in London, or trivial links to others, so we recommend taking the tube to get to the venue.

If you haven't already, please signup and submit talks using the official workshop site: https://act.yapc.eu/lpw2024/

Thanks to this year's sponsors, without whom LPW would not happen:

If you would like to sponsor LPW then please have a look at the options here: https://act.yapc.eu/lpw2024/sponsoring.html

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.