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});

Perl weekly challenge 102

Here are solutions to this weeks challenges from the Perl Weekly Challenge.

You can find my full code on Github

Task 1: Rare Numbers

You are given a positive integer $N. Write a script to generate all Rare numbers of size $N if exists. Please checkout the page for more information about it.

Examples:

  • 2 digits: 65
  • 6 digits: 621,770
  • 9 digits: 281,089,082

The solution

There is a very naive solution to this problem.

Gzip::Zopfli - another compression module

Following on from the Gzip::Libdeflate I mentioned before, I also made this: Gzip::Zopfli

It is based on the Zopfli gzip compression library from Google Research.

Both Zopfli and libdeflate seem to excel at compressing JSON files compared to the ordinary zlib compression, sometimes with an improvement of up to 30%. Zopfli usually wins by a small margin over libdeflate. Here are some results of this script on random JSON files:

rt.cpan.org to remain online

Despite rt.cpan.org still displaying the sunset message, it is in fact not going away forever on the 1st of March, but will have an 'extended downtime' while it is moved elsewhere. In future it'd be nice if communications of such things, and even allowing others to have a say on the matter, could be handled better.

See also:

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:

Inline::F2003

Hi all,

I started the Inline::F2003 project in 2017 because I have a strong interest in modern Fortran and Perl programming.

The project features the Perl module Inline::F2003. This module allows modern Fortran source to be inlined and called from a Perl program. The module compiles the Fortran source and builds an executable shared library that is loaded into the Perl system.

Inline::F2003 is usually invoked at compile-time. The source fragment below shows typical use of the module.

An easy way to use WebSockets?

It's often (for work or for personal projects) that I need to create a real-time feature for a website. This can range from a simple notification whenever an event happens on the server of an existing website, to implementing a real-time multiplayer game or adding a feature inspired from social media websites.

Unfortunately the increase in complexity in code (Perl & JS) and architecture involved in setting up a reliable solution, very often made me forego the opportunity to use WebSockets for many of these projects, and instead resorted to http polling to keep the solution simple for the others to maintain.

So I started looking for a library with a client & server component, that would make life easier. The library would hopefully have to have the following features:

Perl weekly challenge 100

We are finally here - we have hit week 100 of Manwar's Perl Weekly Challenges, and here are solutions to this weeks challenges from the Perl Weekly Challenge.

You can find my full code on Github

Task 1: Fun time

You are given a time (12 hour / 24 hour). Write a script to convert the given time from 12 hour format to 24 hour format and vice versa. Ideally we expect a one-liner.
Example 1: Input: 05:15 pm or 05:15pm -> Output: 17:15
Example 2: Input: 19:15               -> Output: 07:15 pm or 07:15pm

The solution

Firstly I have to thank Manwar for asking for a one line solution as this is my modus operandi .... So we will look at this and see how we can get a simple yet compact solution... well here goes.... {code is 110 bytes, within the functions curly braces there are just 102 bytes of code}

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:

berrybrew version 1.33 released!

I've released berrybrew version 1.33. This version has significant enhancements, along with some bug fixes and handling of some uncaught exceptions. The changes reflect versions 1.30 to 1.33.

Major changes include:

UI:

  • Allows you to install, switch to, remove and use Strawberry Perls directly
  • Can now spawn a CLI window for any Perl you have installed
  • Allows you to spawn a CLI window for the currently active Perl
  • Provides access to modify several of the core configuration options (debug, file association etc)
  • Allows you to disable all berrybrew Perls and restore to system default

Installer:

  • Performs an upgrade on any previous berrybrew install
  • Adds any new configuration options, while preserving the values of any previously set existing ones
  • Provides facility to install the most recent version of Strawberry Perl
  • Allows you to have berrybrew manage the .pl file association
  • Allows you to have the UI run at system startup
  • Aborts if trying to install the same version that's already installed

Functionality:

  • You can now leave off the 32/64 bit prefix on a Perl name, and we'll default to _64
  • All execution paths return a proper exit code
  • Added new berrybrew hidden command, lists all, well, hidden commands

For all other changes, please refer to the Changes file.

Cheers!

-stevieb

Perl 7: A Modest Proposal

I've written a new blog post on Perl 7 (prev: Perl 7: A Risk-Benefit Analysis and Perl 7 By Default). You can find it, and likely my future posts, on dev.to#perl, for similar reasons as mentioned here.

Perl 7: A Modest Proposal

You can now use the spvmcc command to generate an executable file from the SPVM source code.

You can now use the spvmcc command to generate an executable file from the SPVM source code.

SPVM is a module that can convert Perl-like source code into C language and execute it.

I have succeeded in generating an executable in a very stable way.

SPVM source code

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

Who you gonna call? Perl client and website for Google Civic Information API

I recently became aware of a very cool service provided by the Google. The Civic Information API provides contact information for all elected representatives (from head of state down to municipal official) for any US address.

I wrote the Perl client for the API, published as Net::Google::CivicInformation. Get a free API token and you're up and running.

This was a satisfying project because I can imagine people finding actual value in the product. I'm all for being vocal with our government! I decided to take it a step further and created a webservice interfacing to the API. It's written in Dancer2 and the source code is on Github (at the urging of ++GabSzab who pointed out that there are few examples of Dancer2 apps for developers to study.)

The site is online now at https://contactmyreps.com. Please give it a try. Feedback welcome!

cmr.png

Perl weekly challenge 98

Here are solutions to this weeks challenges from the Perl Weekly Challenge.

You can find my full code on Github

Challenge 1

You are given file $FILE.

Create subroutine readN($FILE, $number) returns the first n-characters and moves the pointer to the (n+1)th character.

Solution

Rather than turning this into an object which was the first idea - I decided to keep the code clean by making it a function call, and to also make it work with multiple file handles open simultaneously.

To achieve this without an object - we will need to use a global hash to contain the opened file handles - so that when we re-call the function we don't re-open the file.

Monthly Report - January

Let's look at the brighter side ...

Did you have chance to read my annual report?

I have been doing monthly report for many years now.

Why? What is the point?

Well, let me answer the first question, Why? To be honest with you, I do it to keep myself motivated. I need some kind of (self) motivation to carry on what I do on a daily basis. Now to answer the second question, What is the point? It helps me to keep track and follow the progress.

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.

I found the truth about GameStop, Qanon, the Biden adminstration, and the British Royal Family

The British Royal Family and GameStop have been in a secret war with each other for hundreds of years. Nobody knows why. GameStop has included it in their manifesto and the Royals is always untrustworthy. They leave clues to mock us! GAMESTOP HAS INCLUDED IT IN THEIR MANIFESTO! MOCK! MOCK!

There is more:

Q found out that reincarnation is true and he has been imprisoned in The Pentagon. Qanon are protecting this secret. The Biden administration knows the truth but Qanon have paid them off with a warehouse full of holy water. The Wikipedia entry for The Pentagon keeps getting edited by the Biden administration and Qanon even admit it. They leave clues to mock us.

You too can find out the truth about what's REALLY going on here or here

Perl weekly challenge 101

Here are solutions to this weeks challenges from the Perl Weekly Challenge.

You can find my full code on Github

Task 1: Pack a Spiral

You are given an array @A of items (integers say, but they can be anything).

Your task is to pack that array into an MxN matrix spirally counterclockwise, as tightly as possible.

‘Tightly’ means the absolute value |M-N| of the difference has to be as small as possible.

Dancer2 0.300005 Released

Well, it’s been a hot minute since the last release, hasn’t it? Dancer2 0.300005 has landed on CPAN and features a number of bug fixes, enhancements, and doc patches:

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.