TWC 148: Numbrs, and Cubic Cards

In which we see that you can spell "numbers" without an e, and realize that first implies an ordering.

Perl Weekly Challenge 202: Consecutive Odds and Widest Valley

These are some answers to the Week 202 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 February 5, 2023 at 23:59). This blog post offers some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 1: Consecutive Odds

You are given an array of integers.

Write a script to print 1 if there are THREE consecutive odds in the given array otherwise print 0.

Example 1

Input: @array = (1,5,3,6)
Output: 1

Example 2

Input: @array = (2,6,3,5)
Output: 0

Example 3

Input: @array = (1,2,3,4)
Output: 0

Example 4

United Domains unterstützt den Deutschen Perl Workshop 2022

united domains, das ist ein Team von rund 80 qualifizierten und erfahrenen Mitarbeiterinnen und Mitarbeitern, die sich zuverlässig und mit Leidenschaft um Ihre Domains kümmern. Unser Versprechen lautet: »Die besten Adressen fürs Web«. Denn wir sind überzeugt, dass es einen Unterschied macht, wer Ihre Domains betreut. united-domains ist mit mehr als 1,6 Millionen registrierten Domains und mehr als 300.000 zufriedenen Kunden einer der führenden Domain-Registrare in Europa. Wir bieten über 850 Domain-Endungen: Von .ag wie Antigua bis .za für Südafrika oder neue Domain-Endungen wie .app oder .dev. Der weltweite Domain-Check, eine schnelle und sichere Domain-Registrierung und die übersichtliche Domain-Verwaltung sind unsere Markenzeichen.

Call for Papers, Perl & Raku Conference in Houston 2022

CFP closes March 1st, 2022 10am PST

"The Perl & Raku Conference is a high-quality, inexpensive, technical Conference that celebrates the family of Perl programming languages. The beauty of the conference is that it remains accessible to everyone regardless of experience, yet it is still valuable to the most skilled programmers.
The Perl & Raku Conference 2022 will be held in Houston, TX from June 21-25, 2022. The main conference will be June 22-24, 2022 with tutorials on June 21 and 25."

CFP: https://www.papercall.io/tprchou22

Conference: https://perlconference.us/tprc-2022-hou/

My Favorite Warnings: qw

When I first came to Perl I thought the qw{} construction was pretty neat. Give it a bunch of white-space-delimited text and it gives you back a list separated on the blanks. So

say for qw{ Fee fie foe fum! };

prints 'Fee', 'fie', 'foe', and 'fum!', each on its own line. But if you add punctuation, and warnings are enabled,

say for qw{ Fee, fie, foe, fum! };

gets you 'Possible attempt to separate words with commas ...'.

For a while, I was dealing with this using a weird assortment of quoting techniques. But then I discovered how to tell Perl I meant to do that:

no warnings 'qw';

Perl Weekly Challenge 201: Missing Numbers

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

You are given an array of unique numbers.

Write a script to find out all missing numbers in the range 0..$n where $n is the array size.

Example 1

Input: @array = (0,1,3)
Output: 2

The array size i.e. total element count is 3, so the range is 0..3.
The missing number is 2 in the given array.

Example 2

Input: @array = (0,1)
Output: 2

The array size is 2, therefore the range is 0..2.
The missing number is 2.

Missing Numbers in Raku

Rother OSS GmbH / OTOBO unterstützt den Deutschen Perl/Raku-Workshop 12/01/22

Seit 2011 setzt die Rother OSS GmbH mit Sitz in Süddeutschland und über das ganze Land verteiltem Team auf die Kombination aus OS-Ticketsystem und Business Services vom Experten. Konkret: Consulting, Entwicklung und Support zu den freien OTRS-Versionen.

TWC 147: Prime without Left, and Pent without Quad

In which we bravely overcome ambiguity, and dodge two approaches in the face of (O³).

Do-It-Yourself warnings categories

One of the reasons I have not "moved on" from Perl to some other more "modern" language is that Perl gives me such great access to its inner workings. The Do-It-Yourself Lexical Pragmas post from a couple weeks ago is an example of this. Another example is that Perl lets you tie your own code into its warnings system.

Tying into the warnings machinery requires a module. That is, the interface assumes you are reporting problems relative to another name space that invoked your code. Your module can either add diagnostics to existing Perl warning categories or actually create new categories. In either case your diagnostics are sensitive to the enablement or disablement of the category, as well as its fatalization.

In addition to enabling or disabling warning categories, use warnings ... and no warnings ...; make some subroutines available which can be used to issue your own diagnostics. These are reported relative to the file and line that called into your module (sort of like carp()). A useful subset of the warnings:: subroutines is:

Perl Weekly Challenge 200: Arithmetic Slices and Seven Segment Display

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days from now (on January 22, 2023 at 23:59). This blog post offers some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 1: Arithmetic Slices

You are given an array of integers.

Write a script to find out all Arithmetic Slices for the given array of integers.

An integer array is called arithmetic if it has at least 3 elements and the differences between any three consecutive elements are the same.

Example 1

Input: @array = (1,2,3,4)
Output: (1,2,3), (2,3,4), (1,2,3,4)

Example 2

Input: @array = (2)
Output: () as no slice found.

Arithmetic Slices in Raku

Perl is not dead

Came across an interesting video from one of the users of Perl: Is Perl dead? @Randal L. Schwartz on Dart and Flutter @Code Maven

TWC 146: 10K Prime and CW Trees

In which we leap tall primes in a single bound, mis-take a tree, test percussion, and find the limits of a Curious Module.

Task 1: 10001st Prime Number - One-liners (expanded) in Raku and Perl.

Task 2: Curious Fraction Tree - Solutions in Raku and Perl (with 200+ tests), and another Perl solution using a CPAN module.

To whom this MySQL UTF-8 news may concern

Strictly speaking not news exactly, given that it dates from early 2018, but it was news to me, and since I haven’t seen it make the rounds I still find it worth disseminating. From the MySQL 8.0.11 release notes:

The utf8mb3 character set will be replaced by utf8mb4 in a future MySQL version. The utf8 character set is currently an alias for utf8mb3, but will at that point become a reference to utf8mb4. To avoid ambiguity about the meaning of utf8, consider specifying utf8mb4 explicitly for character set references instead of utf8.

This a declaration of intent rather than a change that has happened… but still. It’s been a very long September

(To prepare for this you’ll want to note what you need to take into account regarding the way utf8mb4 and indexes interact.)

Perl Weekly Challenge 199: Good Pairs and Good Triplets

These are some answers to the Week 199 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 January 15, 2023 at 23:59). This blog post offers some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Contrary to usual, I started with the Perl implementations this week (not having Raku installed on the computer where I started to work on the challenge). So I’ll present the Perl implementations first.

Task 1: Good Pairs

You are given a list of integers, @list.

Write a script to find the total count of Good Pairs.

A pair (i, j) is called good if list[i] == list[j] and i < j.

Example 1

Eertree: Palindromic Tree

The Weekly Challenge 145

The Task 2 of the Weekly Challenge #145 asked us to build a Palindromic Tree. It also linked to a blog post explaining the "Eertree" data structure.

Maybe it was just me, but I found the blog post confusing. Fortunately, it further linked to a scientific paper that introduced the structure around 2014.

My Favorite Warnings: closure

In the context of Perl, a closure is a piece of code that captures a specific instance of a lexical variable. A blog entry a month or so ago explores this in greater detail. If you review this blog entry, though, note that it does not cover lexical subroutines, which act more like anonymous subroutines even though they are named.

This blog entry, though, covers the closure warnings category.

This category has been around since warnings were introduced in Perl 5.6. I find four diagnostics in this category as of Perl 5.34.0; two related to lexical variables and two related to lexical subroutines. The "Variable" and "Subroutine" versions of these have similar causes, so I will not distinguish them in my discussion.

All of these diagnostics seem to arise from the fact that named, non-lexical subroutines are created at compile time, whereas lexical and anonymous subroutines are created at run time.

Opening Files Quickly from Inside vim

I use ot a lot when it comes to opening files. I wanted to be able to use this tool from inside vim as well. It turns out, the solution is quite simple.

Full post: https://www.olafalders.com/2022/01/05/open-this-file-from-inside-vim/

Perl Weekly Challenge 198: Max Gap and Prime Count

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

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

Task 1: Max Gap

You are given a list of integers, @list.

Write a script to find the total pairs in the sorted list where 2 consecutive elements has the max gap. If the list contains less than 2 elements then return 0.

Example 1

Input:  @list = (2,5,8,1)
Output: 2

Since the sorted list (1,2,5,8) has 2 such pairs (2,5) and (5,8)

Example 2

TWC 146: 10K Prime and CW Trees (redirect)

Please go here instead.

Writing a SNES assembler compiler/disassembler - Day 4

Testing

It's time to test what we have written so far. If you look at the asar project, there are already some test files and they come with their own test syntax. It's actually pretty neat since it's embedded in the ASM files comments, so you don't need to write specific tests files.

The format is documented here https://github.com/RPGHacker/asar#test-format but for now, we will just keep the offset and byte value part.

Testing grammar

We could write a loop with like files.IO.slurp.lines and be done to handle this. But let use again a grammar. No action associated with it since it's very basic.

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.