Perl Weekly Challenge #211

A couple very very last-minute solutions to the Weekly Challenge #211. I was crammed for time, so I didn't get to these until the last minute.

Challenge #1

For challenge number 1 I had an idea of the method I would use, but since I've been experimenting with it anyway, I asked ChatGPT for its ideas as well. Because of my lack of time, I wanted to get some help with the design process. ChatGPT is amazing at both developing and describing an algorithm in simple terms to make it understandable. I based my solution somewhat off the AI's algorithm, but I did write it entirely by hand. It's pretty simple, it just iterates across the matrix and makes sure everything matches its diagonal neighbor prior to it.

Another thing you might notice this week is that I actually put my solutions into functions, not just a basic script. Anyways, here it is:

Perl Weekly Challenge 252: Unique Sum Zero

These are some answers to the Week 252, 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 January 21, 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: Unique Sum Zero

You are given an integer, $n.

Write a script to find an array containing $n unique integers such that they add up to zero.

Example 1

Input: $n = 5
Output: (-7, -1, 1, 3, 4)

Two other possible solutions could be as below:
(-5, -1, 1, 2, 3) and (-3, -1, 2, -2, 4).

Example 2

This week in PSC (103) | 2023-04-07

Paul, Philippe, and Ricardo had our mostly-weekly Zoom call today.

We began by discussing last week, when Pete K from TPRF joined us and we talked about what TPRF could do to help p5p. (Main topics then, which didn’t get any firm action items, were support for critical infrastructure and services and bounties for implementation of PPCs.)

Most of our time this week was spent on the upcoming v5.38.0 release, especially what might be blocking it. (Notable: two new deprecation warnings added in the last two releases — smartmatch, and tick as package separator.)

We discussed strategies used by other languages to make things more attractive for developers, like batteries included. We didn’t end up with any plan of action from this.

In a few weeks, we’ll all be in one place, and look forward to looking carefully at the color of Chartreuse.

Web::Scraper - Weekly Travelling in CPAN

Destination: Web::Scraper
Date of Latest Release: Oct 20, 2014
Distribution: Web-Scraper
Module version: 0.38
Main Contributors: Tatsuhiko Miyagawa (MIYAGAWA)
License: [perl_5]

The official document provided by Web::Scraper is quite clear. I copied the style and comments and made up a script :

Increasing Perl’s Visibility, Redux

Quite a while ago, I blogged about how Perl projects should have websites to increase not only their visibility, but the visibility of Perl as a whole.

Perl has had the CPAN and awesome websites like MetaCPAN and its predecessor search.cpan.org for a long time, so unlike how things happen in other programming language ecosystems, many Perl projects have felt no need to start their own websites for documentation, package downloads, and community — all these things were already provided.

However, I do feel that this centralization keeps Perl content on the Internet very isolated and makes Perl less visible than other programming languages.

Perl Weekly Challenge 252: Special Numbers

These are some answers to the Week 252, 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 January 21, 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: Special Numbers

You are given an array of integers, @ints.

Write a script to find the sum of the squares of all special elements of the given array.

An element $int[i] of @ints is called special if i divides n, i.e. n % i == 0, where n is the length of the given array. Also the array is 1-indexed for the task.

Example 1

How to change charset=ISO-8859-1 to charset=UTF8? Rocky 9.1 server

Hi ! Everyone, I am back here to ask environmental issue.
When I ran the following CGI.pm testing script before placing at /var/www/cgi-bin, but it is still at /home/mkido/bin. Perl script ran successfully at the Terminal, and replied back the OUTPUT below there.

Perl Script, check.pl
#!/usr/bin/env perl
use strict;
use warnings;
use CGI;

my $q = CGI->new;
print $q->header();
print "OK";

===================
OUTPUT
mkido@localhost$check.pl [Enter to run it.]
Content-Type: text/html; charset=ISO-8859-1

OK
mkido@localhost$


This output result evoked my recognition. Is this Rocky 9.1 Web Server running to provide charset=ISO-8859-1 ?? I want to set all replies from the Server to charset=UTF-8. The httpd.conf is already set to charset=UTF-8. Is there any other setting adjustment somewhere in environmental configuration on my server to change from charset=ISO-8859-1 to charset=UTF-8 ?? Thanks, thanks.

Weather::WeatherKit and Weather::Astro7Timer

Today, the popular Dark Sky weather API is shutting down. I did a little write-up for non-Perl devs on DEV.to, but I thought I'd post here a couple of potentially useful modules I released to CPAN recently. 

Weather::WeatherKit accesses the WeatherKit REST API, which is Apple's official Dark Sky replacement. The module uses Crypt::JWT to create tokens, so accessing WeatherKit then is as simple as:

use Weather::WeatherKit;

my $wk = Weather::WeatherKit->new(
    team_id    => $apple_team_id,
    service_id => $weatherkit_service_id,
    key_id     => $key_id,
    key        => $private_key
);

my %report = $wk->get(
    lat      => 51.2,
    lon      => -1.8,
    dataSets => 'currentWeather'
);

Of course, this API is sort of free, as it requires an Apple developer account. If you don't have one and don't want to get one, there are some alternative APIs, but for the purposes of this post I'll stick to 7Timer, via Weather::Astro7Timer. Even simpler, as it does not need authentication:

Graph - Weekly Travelling in CPAN

Destination: Graph
Date of Latest Release: Feb 12, 2023
Distribution: Graph
Module version: 0.9726
Main Contributors: Jarkko Hietaniemi (JHI)
Current Maintainer: Neil Bowers (NEILB)
License: [perl_5]

an_undirected_graph.png

Long time ago I claimed in front of a friend I would write a short introduction to graph theory, but I had been not able to figure out where I should start. Neither I would try today. The mathematical objects graphs, or the abstract data structures graphs, are full of interesting behaviors being studied in the discrete math subdiscipline graph theory. The CPAN module Graph is designed to empower Perl programmers doodle with undirected graphs and directed graphs (and also multigraphs and hypergraphs - not going to visit these functionalities here).

Perl Weekly Challenge 251: Lucky Number

These are some answers to the Week 251, 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 January 14, 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: Lucky Number

You are given a m x n matrix of distinct numbers.

Write a script to return the lucky number, if there is one, or -1 if not.

A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.

Example 1

Perl Weekly Challenge #210

I'm back this week with PWC #210. Last week I was very busy and spent a long time reviewing other peoples' far more efficient solutions to #208, so I didn't get to doing any solutions for #209. The usual disclaimer about this could contain spoilers, so if you're trying to solve the challenge yourself you may want to skip this post for now. So let's get right into this.

Kill And Win

For this challenge I decided to use some of the tools I learned about in the solutions other people submitted for #208, especially the ways hashes can make the process more efficient. The goal is to find the number in the list where you can delete the most points by deleting the number and its adjacent numbers plus and minus one. You get to count each number however many times it appears in the list.

Introducing Exporter::Almighty

Consider a simple module like this:

This week in PSC (102) | 2023-03-24

Topics discussed:

  • Bug reporting by email: we commit to nothing as an organisation. Some would-be submitters of issues don’t want to use GitHub. They can just send an email to perl5-porters and hope that some helpful soul will copy-paste to GitHub. We encourage the conventional use of GitHub.
  • On the topic email bug reports, it’s likely time to deprecate perlbug as a way to send bug reports. It could be updated to point the user to GitHub, and to print perl -V output (etc.) to copy and paste. We should also have a better set of templates for issues on GitHub.
  • The segfaults on feature-class and refaliasing won’t be fixed before 5.38, and should just be documented as “known bugs”
  • After we discussed renaming RFC to PPC, the general sentiment seemed to be “in favor”, so we’re going to make the rename
  • Rik volunteered to release 5.38, we still need a release manager for 5.37.11
  • Some discussions about preparing the Perl Toolchain Summit plans (which will host the first ever in-person PSC meeting)

Perl Weekly Challenge 251: Concatenation Value

These are some answers to the Week 251, 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 January 14, 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: Concatenation Value

You are given an array of integers, @ints.

Write a script to find the concatenation value of the given array.

The concatenation of two numbers is the number formed by concatenating their numerals.

Text::Extract::Word, MsOffice::Word::Surgeon - Weekly Travelling in CPAN

Destination: Text::Extract::Word
Date of Latest Release: Mar 09, 2012
Distribution: Text::Extract::Word
Module version: 0.02
Main Contributors: Stuart Watt (SNKWATT)
License: The Artistic License 2.0
Date of Latest Release: Jan 26, 2023
Distribution: MsOffice::Word::Surgeon
Module version: 2.01
Main Contributors: Laurent Dami (DAMI)
License: The Artistic License 2.0

Notice

Perl Weekly Challenge #208

First of all, a greeting. I posted an introduction with a notification of intent to take over a module on CPAN, but the maintainer responded to me. I'm Avery, I'm developing SeekMIDI, a small graphical MIDI sequencer. I started it in 2016 and I took a long break from programming entirely, and I've just restarted developing my programming skills again. For starters, I'm working on Perl Weekly Challenges and bug fixes to modules.

Without further ado, here are my solutions to the PWC #208. All solutions are about to be posted, but this could be a spoiler if you're trying to solve it too. I was very pleased this week that I got it down to about 15-25 minutes for each task, so I'm definitely getting more comfortable in Perl again.

First, task 1:

The first line of Perl_CGI script, env perl vs perl only, how different?

Hi ! Everyone there ! How are you ?

Until recently I runs all of my Perl scripts as well as Perl_CGI scripts by starting the folowing salutation,

#! /usr/bin/perl -w

The script with this beginning runs well at BASH shell at (/home/mkido/bin) LINUX such as Fedora, Ubuntu, Rocky (Alma-derivative). However, almost right now I noticed some of Perl example around has the different first line as below,

#! /usr/bin/env perl

And it doesn't seem to run at HOME BASH shell (/home/mkido/bin) by simple way of executing it by-itself by the command line. Will someone explain me about what is this [env perl] stuff? Thank you so much.

Mitsuru Kido

Perl Weekly Challenge 250: Alphanumeric String Value

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

Task 1: Alphanumeric String Value

You are given an array of alphanumeric strings.

Write a script to return the maximum value of alphanumeric string in the given array.

The value of alphanumeric string can be defined as

a) The numeric representation of the string in base 10 if it is made up of digits only. b) otherwise the length of the string

Example 1

Experiments in Overloading

Let's play with overloading a little.

A simple class:

  package Local::Overloaded {
    use Moo;
    
    has number => ( is => 'ro' );
    
    use overload '0+' => sub {
      my $self = shift;
      return $self->number;
    };
  }

And let's test it:

  use Test2::V0;
  my $obj = Local::Overloaded->new( number => 42 );
  is( 0+$obj, 42 );
  done_testing;

This test fails.

Why?

This week in PSC (101) | 2023-03-17

Porters,

We had an abbreviated PSC call today, largely due to an unexpected delay.

We discussed offering split-up deprecation categories, so you can no warnings 'deprecated::.xyz' and re-affirmed that we want to do this.

We talked about improving the backcompat of strict-vs-version behavior for use vX where X is older than v5.36 and agreed we’d bring that back, but wanted to discuss more about other related changes to the use-vX code.

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.