Perl Weekly Challenge 164: Prime Palindromes and Happy Numbers

These are some answers to the Week 164 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 May 15, 2022 at 24:00). 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: Prime Palindromes

Write a script to find all prime numbers less than 1000, which are also palindromes in base 10. Palindromic numbers are numbers whose digits are the same in reverse. For example, 313 is a palindromic prime, but 337 is not, even though 733 (337 reversed) is also prime.

Prime Palindromes in Raku

We use a data pipeline (chained method invocations) with two grep statements, one to keep palindromes and one to keep prime numbers. This leads to a fairly concise one-line solution:

say (1..^1000).grep({ $_ == .flip }).grep({.is-prime});

My Favorite Modules: Errno

The open or die idiom is fairly ubiquitous in Perl. To be useful, the exception should say something about what went wrong: open ... or die "Open error: $!", for example.

The $! built-in variable (a.k.a. $ERRNO or $OS_ERROR if use English; is in effect) gives you access to the C language errno variable, which through the magic of Perl interpolates an error message appropriate to the error given.

But there are times when some error analysis is in order. Fortunately, $! is a dualvar, so if you access it in numeric context rather than string context, you get the actual numeric value of the error code. But for both portability and maintainability you don't want to compare $! to a numeric literal. Thus, Errno. For example:

TWC Episode 154 - Padawan Missing

In which we search for a needle in a lendee
(or maybe a chatchka in a haystack),
and delight in some lazy CPAN comfort.

Cloud Provider Performance Comparison - Perl & more

Last year, impressed with the apparent speed of an M1 Mac Mini I bought to try out, I explored its perl performance and wrote about it in a  blog post . I used mainly my own benchmarks which were mostly representative of workloads I was interested in.

Perl Weekly Challenge 163: Sum Bitwise Operator and Summations

These are some answers to the Week 163 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 May 8, 2022 at 24:00). 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: Sum Bitwise Operator

You are given list positive numbers, @n.

Write script to calculate the sum of bitwise & operator for all unique pairs.

Example 1:

Input: @n = (1, 2, 3)
Output: 3

Since (1 & 2) + (2 & 3) + (1 & 3) => 0 + 2 + 1 =>  3.

Example 2:

I start to write the book "Perl for Beginners to Mastering Perl in a week"

I start to write the book "Perl for Beginners to Mastering Perl in a week".

I wrote two Japanese books from a years ago.

Perlテキスト処理のエッセンス

PerlでポータブルなLinuxファイル管理入門

Finally, I decided to write English books.

Recently it becomes easy to publish both e-books and paperbacks.

The title of my first English Perl book is "Perl for Beginners to Mastering Perl in a week".

This book is for Perl beginners to learn Perl quickly.

My Favorite Modules: Devel::NYTProf

'It is a capital mistake to theorize before one has data.' -- Sherlock Holmes, "A Scandal in Bohemia"

The mental excursion that led to this blog post started with a report from Olaf Alders that my Perl::Critic::Policy::Variables::ProhibitUnusedVarsStricter was generating a false positive on variables used only as defaults in subroutine signatures. After the first cut at fixing this I thought a regression test was in order. I did this by running both unpatched and patched versions of the policy against my Mini CPAN, and then diff on the outputs.

This has always taken the better part of a day to run, and given that it had to expand all the distributions first and then run a fairly brute-force policy against anything it found, I accepted this as the price of conscientiousness.

Finding unused variables in your Perl code

I've put together a brief overview of some of the ways to automate finding unused variables in your Perl code:

https://www.olafalders.com/2022/02/22/finding-unused-perl-variables/

Perl Weekly Challenge 162: ISBN-13 and Wheatstone-Playfair

These are some answers to the Week 162 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 May 1st, 2022 at 24:00). 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: ISBN-13

Write a script to generate the check digit of given ISBN-13 code. Please refer wikipedia for more information.

Example

ISBN-13 check digit for '978-0-306-40615-7' is 7.

This how Wikipedia describes the calculation of the ISBN-13 check digit:

The progress of the SPVM language 2022

Hi, I write the progress of the SPVM module 2022.

SPVM is a programming language that is build on top of the Perl ecosystem and provides fast calculation and array operation to Perl.

SPVM can be transpiled to C language, and it can be compiled to shared libraries and executable files.

SPVM can call C/C++/Cuda libraries by writing pure C/C++/Cuda language without XS.

I wrote SPVM from 2016. I finally implement the all features that I think they are needed for modern applications.

Next, I need to do many tests of SPVM module by creating modules and applications.

Documentations

The following are the official documentations of SPVM.

SPVM

Tutorial

SPVM Tutorial.

Tutorial

Language Specification

SPVM Language Specification.

Language Specification

Standard Functions

SPVM Standard Functions

Standard Functions

Standard Modules

SPVM Standard Modules.

Standard Modules

Performance Benchmark

SPVM Performance Benchmark.

Benchmark

Exchange API

SPVM Exchange API converts Perl data structures to SPVM data structures, and vice versa.

ExchangeAPI

Native API

SPVM Native API is C API used in SPVM native method.

NativeAPI

Some tricks for prettier xs

XS has a reputation of being ugly and cumbersome, but in my experience, it doesn't have to be. Let's take for example this snippet from my Thread::Csp::Promise class:

MODULE = Thread::Csp PACKAGE = Thread::Csp::Promise PREFIX = promise_

SV* promise_get(Promise* promise)

bool promise_is_finished(Promise* promise)

SV* promise_get_notifier(Promise* promise)

Please help test big pull request for DBD::Oracle

This large pull request hopes to solve segfault at cleanup and problems with multiple charsets in multiple connections to Oracle.

If you use DBD::Oracle please grab the PR and give it a try, then send your feedback.

https://github.com/perl5-dbi/DBD-Oracle/pull/147

Perl Weekly Challenge 161: Abecedarian Words and Pangrams

These are some answers to the Week 161 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 April 24, 2022 at 24:00). 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: Abecedarian Words

An abecedarian word is a word whose letters are arranged in alphabetical order. For example, “knotty” is an abecedarian word, but “knots” is not. Output or return a list of all abecedarian words in the dictionary, sorted in decreasing order of length.

Optionally, using only abecedarian words, leave a short comment in your code to make your reviewer smile.

Abecedarian Words in Raku

My Favorite Warnings: regexp

'A fair jaw-cracker dwarf-language must be.' -- Samwise Gamgee, The Lord of the Rings, II/iii: "The Ring Goes South", as quoted in regcomp.c, the Perl regular expression compiler.

As you would expect, this category gets you warnings about possibly-problematic regular expression constructions. A couple specific examples are:

Assuming NOT a POSIX class ...

This warning is about things that look kind of like POSIX character classes, but do not parse that way. The full diagnostic gives examples like [[:alnum]] (missing colon) and [[:digit:xyz] (missing right square bracket). These parse like simple character classes ([:[almnu]\] and [:[dgitxyz] respectively), so without the warning you get a hard-to-diagnose bug.

Unescaped left brace in regex is passed through ...

Efforts to eliminate unescaped left braces so that they are available for new syntax have been underway since 5.17.0, released May 2012. As I recall, this effort turned to be much harder than originally anticipated because at least one toolchain external to Perl (autoconf if memory serves) relied on this behavior.

Strato unterstützt den Deutschen Perl/Raku Workshop 2022

Wer sind wir?

1997 gegründet, gehört STRATO mit über 4 Millionen Domains und mehr als 2 Millionen Kunden heute zu den größten Webhosting-Anbietern weltweit. STRATO beschäftigt rund 500 Mitarbeiter und betreibt zwei TÜV-zertifizierte Rechenzentren mit über 70.000 Servern in Berlin und Karlsruhe. Die STRATO AG ist ein Unternehmen der United Internet-Gruppe.

Wo brauchen wir Deine Perl-Kenntnisse?

TWC 150: bAbAbbAb and a few Composites

In which we see Leonardo outside his native Nums, and that the World is not made of Ones.

(Placeholder; still editing)

TWC Task #1 - Fibonacci Words

Raku

Perl

Dart

TWC Task #2 - Square-free Integer

Raku

Perl

Dart

Perl Weekly Challenge 160: Four is Magic and Equilibrium Index

These are some answers to the Week 160 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 April 17, 2022 at 24:00). 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: Four is Magic

You are given a positive number, $n < 10.

Write a script to generate English text sequence starting with the English cardinal representation of the given number, the word ‘is’ and then the English cardinal representation of the count of characters that made up the first word, followed by a comma. Continue until you reach four.

Example 1:

Input: $n = 5
Output: Five is four, four is magic.

Example 2:

Input: $n = 7
Output: Seven is five, five is four, four is magic.

Installing Perl: A Chicken-and-Egg Problem

A couple days ago the SD card on a Raspberry Pi lost its beady little mind, and I ended up rebuilding the system from scratch. I generally build my own Perl (also from scratch) and then install the modules I need. So that I can have a log file to rummage through in the event of a problem, I start by configuring the CPAN client interactively, and then doing

$ cpan YAML 2>&1 | tee YAML.log
$ cpan Bundle::CPAN 2>&1 | tee YAML.log

Normally I would now install the modules specific to my use. But when I tried this time I got

HTTP::Tiny failed with an internal error: IO::Socket::SSL 1.42 must be installed for https support
Net::SSLeay 1.49 must be installed for https support

Annual Report - 2021

Good bye 2021 and Welcome 2022 !!!

Time to look back and review how the year 2021 was for me.

Perl Weekly newsletter

As you all know, I have been editing Perl weekly newsletterGabor Szabo. We agreed, I edit the even numbered newsletter and Gabor would do odd numbered ones. So that way, I got the honour to edit the 500th edition of the weekly newsletter. I am now looking forward to my personal, 100th edition. As of today, I have edited 96 in total.

The [Perl] Weekly Challenge

Thanks to the Team PWC, I completed one more year of weekly challenge. It may not sound a big deal but for me it is. I wouldn't have done without the support of the team. I would like to mention one name, Colin Crain, our in-house, Perl reviewer for the hard work in reviewing Perl solutions every week without fail for so many months now.

TWC 149: Limited Fibs, and Bases of Unusual Size

(Currently editing)

In which we see that you don't need all the Fibs, and have trouble turning 21.

TWC Task #1 - Fibonacci Digit Sum

Given an input $N, generate the first $N numbers for which the sum of their digits is a Fibonacci number.

(i.e. Generate OEIS A028840)

Observations:

Raku

Perl

C

TWC Task #2 - Largest Square

(i.e. Generate OEIS A287298)

Given a number base, derive the largest perfect square with no repeated digits and return it as a string. (For base>10, use ‘A’..‘Z’.)

Observations:

Raku

Perl

C

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.