Alles in Ordnung

Perl returns its hash values in a random order. Since 5.14 or so, the random order changes every time. So if you loop over your hash values, you get a different ordering each time.

for my $k (keys %hash) { }

No problem you say, I'll use sort to order my keys.

for my $k (sort keys %hash) { }

But what if you want to use a non-default order, like case-insensitive? Easy-peasy you claim.

for my $k (sort {uc ($a) cmp uc ($b)} keys %hash) { }

Now here's my problem. I'm using XS to loop through the hash, and I want to sort the keys in the hash according to the user's preference.

Perl Weekly Challenge 147: Truncatable Primes and Pentagon Numbers

These are some answers to the Week 147 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 16, 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: Truncatable Prime

Write a script to generate first 20 left-truncatable prime numbers in base 10.

In number theory, a left-truncatable prime is a prime number which, in a given base, contains no 0, and if the leading left digit is successively removed, then all resulting numbers are primes.

Example:

9137 is one such left-truncatable prime since 9137, 137, 37 and 7 are all prime numbers.

Truncatable Prime in Raku

CY's Brute-Force Take on Task 2 of PWC#089

If you want to challenge yourself on programming, especially on Perl and/or Raku, go to https://perlweeklychallenge.org, code the latest challenge, submit codes on-time (via GitHub or email).



(In a rush, sorry for the "raw" style this week.)


Development community that we can see to development of Perl Part1 - C language specification creating group

The Perl core team seems to be looking for resources to help in language development.

Currently, it seems the material in python.

perlgov: the perl governance document

I feel that Perl and Python cultures are quite different.

It's also based on an improvised document in 2019 when the Python reader quit.

I can understand how envious we are when we see Python attracting users(although
I'm watching a lot of cheating at the same time).

On the other hand Perl has long been a conservative culture.

So, we can refer to the methods used by developers of languages, operating systems and tools that also have a conservative mindset.

The first thing I would like us to refer to is the method used by the group that creates C language specifications.

C language specification creating group

C89, C99, C11

Development of C language has continued some slowly, but functions that users think are lacking have been added.

Specially C99 is added good features I wanted.

It would be worthwhile to ask the C specification group how it was achieved.

I think it's less repulsive and less likely to fail if we adopt a method from a culture similar to Perl rather than a culture opposite to Perl.

Drawing a blank with XS

I spent quite a lot of time trying to work out what this error message meant:

Error: Unterminated '#if/#ifdef/#ifndef' in Libpng.xs, line 1328

The first problem here is that line 1328 is the end of the file, so that wasn't a big help.

After spending a lot of time counting #if and #endif statements in the file over and over again, in the end I had the bright idea of looking at the actual XS output, and managed to find the problem. Apologies for quoting it in full here but I can't think of a good way to truncate it:

Perl Weekly Challenge 146: Prime Numbers and Fraction Tree

These are some answers to the Week 146 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 9, 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: 10001st Prime Number

Write a script to generate the 10001st prime number.

10001st Prime Number in Raku

Raku has a fast is-prime subroutine or method, using the Miller-Rabin algorithm, to test whether a integer is prime. We can just generate an infinite (lazy) list of prime numbers and look for the 10000st one.

use v6;

my @primes = grep { .is-prime }, (1, 2, 3, -> $a { $a + 2} ...Inf);
say @primes[10001 - 1];  # Subtract 1 because the array starts at 0

This script displays the following output:

Monthly Report - November

Welcome last month of the year 2020

Generally, I always look forward to festive month, December. But I don't expect it to be any different from other months, unfortunately.

With so much going on in my personal life, it is hard to focus on anything. One thing that I really miss these days are personal time. I am constantly working on it with the help of experts in the field. I try to look at the positive side of the life but I can't ignore the fact I am not giving 100% to my pet project The Weekly Challenge. Having said that I must thank the entire team for the support and encouragement in this difficult time. As of today, we entered into the 89th week. I can't wait to see when we get to the 100th week.

CY's Take on PWC#088

If you want to challenge yourself on programming, especially on Perl and/or Raku, go to https://perlweeklychallenge.org, code the latest challenges, submit codes on-time (by GitHub or email).


This blogpost is not in shortage of unanswered questions...

Task 1 Array of Product

sub myproduct {
    my @arr = @_;
    my @ans;
    my $pre_prod = 1;   # short for "previous product"
    push @arr1;
    for my $i (0..$#arr-1) {
        my $entry = $pre_prod;
        $entry *= $arr[$_for ($i+1..$#arr);
        $pre_prod *= $arr[$i];
        push @ans$entry;
    }

    return \@ans;
}
The above, I designed, is a prototype for multiplication (and division, if possible) when it is expensive to do mulitplication, such as matrices. Since I don't know much about those algorithmic knowledge, just leave the codes here for personal future digestion.
---
What I have submitted is an one-liner:
perl -e ' for $j (0..scalar @ARGV-1) {$a = 1eval {$a *= $ARGV[$_if $_ != $jfor (0..scalar @ARGV-1); print "$a "; }' 5 2 1 3 4

Perl Weekly Challenge 088

Despite the holiday week here in the U.S., I was able to tackle this week's Perl Weekly Challenge. I have to say that this week's challenge was the most satisfying for me as it allowed me to not only come up with a novel solution (for me!), but it also provided an opportunity for me to leverage two areas of Perl programming that have been a real challenge for me: recursion and references. The deadline to submit solutions for this challenge is fast approaching so if you haven't solved it yourself yet, you may want to come back to this post later.

Task 1

Task #1, "Array of Product", asks the following:

You are given an array of positive integers @N.

Write a script to return an array @M where $M[i] is the product of all elements of @N except the index $N[i].

Example 1:

Perl Weekly Challenge 145: Palindromes

These are some answers to the Week 145 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 2, 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: Dot Product

This first task of this week’s challenge was covered in this blog post.

Task 2: Palindromic Tree

You are given a string $s.

Write a script to create a Palindromic Tree for the given string.

I found this blog explaining Palindromic Tree in detail.

Example 1:

Input: $s = 'redivider'
Output: r redivider e edivide d divid i ivi v

Example 2:

Input: $s = 'deific'
Output: d e i ifi f c

Example 3:

The mysterious case of the SVt_PVIV

The other day I wanted to send my friend some silly emojis on LINE and so I updated my flaky old Unicode browser to the new-fangled Unicode with values above 0x10000, so that I could fetch the Emojis, which start around here. The thing also features a perl script which fetches values from Unicode::UCD using the charinfo function. I also updated to Perl 5.32 around the same time. Now the funny thing was that I started getting all kinds of errors about invalid JSON in the browser console. My Perl script was sending something of the form {... "script":Common ...} from my module JSON::Create, which is not valid JSON due to not having quotes around Common, and obviously my module was faulty.

CY's Take on PWC#087

If you want to challenge yourself on programming, especially on Perl and/or Raku, go to https://perlweeklychallenge.org, code the latest challenges, submit codes on-time (by GitHub or email).

After the long-haul Sudoku Task, this week we come to meet two tiny tasks.

Task 1 Longest Consecutive Sequence

It seems unavoidable for me that we have to sort the input first:

sub long_consec{
    my @list = sort {$a<=>$b@_;
    #...

Then I use a for loop and a temporary list variable @potential_max_opp

    my $max_len = 1;
    my @max_opp;

    my @potential_max_opp = ($list[0]);
    for (1..$#list) { 
        if ($list[$_-1] == $list[$_]-1) {
            push @potential_max_opp$list[$_];
        } else
        {
            if (scalar @potential_max_opp > $max_len) {
                $max_len = scalar @potential_max_opp;
                @max_opp = @potential_max_opp;
            }
            @potential_max_opp = ($list[$_]);
        }
    }

    return \@max_opp;
}

Pretty straight-forward.

Some ideas: There should be some more efficient algorithms, maybe similar to counting sort , if the range of integers is given and the integers are "dense" enough.
---

Where is Rob?

Does anybody know Rob Seegel (aka RCS), the author/maintainer of Tk::MListbox?

I tried to contact the author by e-mail but didn't get any feedback so far.
I would like to adopt the module Tk::MListbox (and the other packages).

Perl Weekly Challenge 145: Dot Product

These are some answers to the Week 145 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 2, 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: Dot Product

You are given 2 arrays of same size, @a and @b.

Write a script to implement Dot Product.

Example:

@a = (1, 2, 3);
@b = (4, 5, 6);

$dot_product = (1 * 4) + (2 * 5) + (3 * 6) => 4 + 10 + 18 => 32

An important point is that we are told that the arrays have the same size. Thus, we don’t need to check that. We’ll also assume that they contain only numbers.

Dot Product in Raku

REST::Neo4p catches up to Neo4j V4.0+

For a long time (since 2012), REST::Neo4p has provided a way for Perlers to play, and even work, with the graph database Neo4j.

Neo4j has made many changes and improvements in its server and its query language in that time. However, as it has become successful commercially, it has made breaking API changes of one kind or another more and more regularly. In the last major release, version 4.0, Neo4j retired the REST endpoint on which REST::Neo4p was based. This endpoint was "entity-based", as it were, allowing direct access to nodes, relationships, and the like via entity IDs. It was well suited to the object (HAR HAR) of REST::Neo4p. But Neo4j decided to focus exclusively on its declarative query language Cypher, and to move away from the "graph walking" paradigm that the REST endpoint represented.

Permutations and Recursion

(Originally published on samirparikh.com.)

I founded a company called Perl Research Institute, Ltd.

I founded a company called Perl Research Institute, Ltd in Japan.

The main purpose of the Perl Research Institute is to restore Perl's honor.

Its reputation was miserable compared to the excellence of Perl's features.

Perl and its users have suffered in many negative campaigns.

Perl was seen by the people who say We are loved in the whole world as an abandoned stone.

I'm not afraid to talk about Perl Even if I'm surrounded by mighty powers who Do a lot of cheating.

Perl Research Institute

Perl Weekly Challenge 144: Semiprimes and Ulam Sequence

These are some answers to the Week 144 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 December 26, 2021 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: Semiprimes

Write a script to generate all Semiprime number <= 100.

For more information about Semiprime, please checkout the Wikipedia page.

In mathematics, a semiprime is a natural number that is the product of exactly two prime numbers. The two primes in the product may equal each other, so the semiprimes include the squares of prime numbers.

Example:

10 is Semiprime as 10 = 2 x 5
15 is Semiprime as 15 = 3 x 5

JSON::Create now features indentation

In version 0.27 of JSON::Create I added a new indentation feature. This was added basically out of necessity. Originally the purpose of the module was sending short bits of JSON over the internet, but I've been using JSON more and more for processing data too. I've spent quite a long time working on a web site for recognition of Chinese, and I've been using JSON more and more extensively. The basic data file for the web site is a 168 megabyte JSON file. Not indenting this kind of file makes for "interesting" problems if one accidentally opens it in an editor or on a terminal screen, a million characters all on one line tends to confuse the best-written text reading utilities. So after years of suffering the relief is tremendous, and now I have tab-based indentation in JSON::Create.

Originally I thought that I should make all kinds of customisable indentation possible, but then it occurred to me that basically any fool armed with a regular expression could easily alter the indentation however they want to. I put a simple example in the documentation.

CY's Take on PWC#086

pascal_userinterface.jpg# (I will write more some hours later. This may not be a good practice. But) #HKT November 15, 2020 3:32 PM

I am excited by the Sudoku task and eager to share.

If you want to challenge yourself on programming, especially on Perl and/or Raku, go to https://perlweeklychallenge.org, code the latest challenge - Challenge 086, submit codes on-time (by GitHub or email).



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.