Perl Weekly Challenge 93: Max Points and Sum Path

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

Spoiler Alert: This weekly challenge deadline is due in a day or so. 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 Points

You are given set of co-ordinates @N.

Write a script to count maximum points on a straight line when given co-ordinates plotted on 2-d plane.

Example 1:

From a Reflection on The Weekly Challenge 092 Task 1

Update: Ben Bullock has provided script for my question.
See the comment section. Thanks Ben.

---------------------

Happy New Year!


Today's data is about

$ perl pwc092-1_isomorphic.pl '茫茫人海' '夜夜笙歌'
0

--

Seeing others' post, I have a short reflection on dated The Weekly Challenge #092 Task 1 (statements / recap ), but may lead to a hike towards a hill in Perl.

Task statement:

TASK #1 › Isomorphic Strings Submitted by: Mohammad S Anwar

You are given two strings $A and $B.

Write a script to check if the given strings are Isomorphic. Print 1 if they are otherwise 0.
Example 1:

Input: $A = "abc"; $B = "xyz"
Output: 1

Example 2:

Input: $A = "abb"; $B = "xyy"
Output: 1

Example 3:

Input: $A = "sum"; $B = "add"
Output: 0


My unsatisfactory code (distaste due to the two subroutines &verify_pattern and &learn_pattern are almost the same).

Suddenly today I want to try out whether the Unicode support is direct; sadly, no:

For a single character:

I'm Making Headway Now

Last January there was a post on reddit which claimed that my module JSON::Parse was not only failing some of the JSON Test Suite tests, but also crashing on one of them. Anyway I should have got around to doing something about it sooner, but here are my conclusions.

First of all there was a crash on one of the files, which went something like this: [{"":[{"":[{"", repeated about 100,000 times. (The actual file is here if you really want to see it.) Investigating it using a LInode, I found that after 80,000 open brackets the stack was overflowing, causing the crash to occur. If I added a printf in the midst of my code the printf would cause the stack overflow, so it wasn't actually due to my code but just because the stack size seems to be quite small on Linux.

Perl weekly challenge 93

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

Spoiler Alert: This weekly challenge deadline is due in a few days (January 3, 2021). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.

I'm not a great blogger - but I will try and explain my solutions to the Perl weekly challenge each week. I always try and look for interesting solutions to the problems at hand.

Part 1

Not sure on the correct way to do this... I first looked at all the pairs of points - and looked to see what the direction was between the points. For those where the y-coordinates are different you can just use (x1-x2)/(y1-y2) to represent the slope. We also that flipping the order of the points gives the same value. For those canses where y is the same - the slop can be represented by an "infinity value" in my case i use "-"

Perl Weekly Challenge 92: Isomorphic Strings and Insert Intervals

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

Spoiler Alert: This weekly challenge deadline is due in a few hours. 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: Isomorphic Strings

You are given two strings $A and $B.

Write a script to check if the given strings are Isomorphic. Print 1 if they are, otherwise 0.

Example 1:

Input: $A = "abc"; $B = "xyz"
Output: 1

Example 2:

Input: $A = "abb"; $B = "xyy"
Output: 1

Example 3:

Input: $A = "sum"; $B = "add"
Output: 0

Isomorphic Strings 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.)


Misusing newSVpv

I managed to cause another set of obscure bugs by misusing newSVpv. The goal of this code is to split the RGB and the alpha (transparent) part of a PNG image, for the use of the PDF::Builder module on CPAN.

Here the SV in newSVpv is "scalar value", and the "pv" means "string". My code says this:

sv = newSVpv ("", len);

and it causes the crash on Solaris and other operating systems because the above statement is a bad idea. What happens is that Perl copies "len" bytes from my string, where "len" might be a very large number, for a large PNG image, but I've given it the string "" to copy from. So Perl tries to copy from uninitialised, or possibly even inaccessible, parts of the computer's memory. I found out my error only after almost giving up, by using valgrind to look for memory errors.

The correct version of this is

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

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 92

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

Spoiler Alert: This weekly challenge deadline is due in a few days (December 27, 2020). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.

I'm not a great blogger - but I will try and explain my solutions to the Perl weekly challenge each week. I always try and look for interesting solutions to the problems at hand.

Part 1

I started with what I thought was the best approach - keeping a hash of the letters in both words and if they don't match the required pattern then to return 0 otherwise return 1. But this looked rather messy. There must be a simpler, more elegant solution.

I thought how would I compare the words, and "normalisation" sprang to mind:

Perl Weekly Challenge 86: Pair Differences and Sudoku Puzzles

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

Spoiler Alert: This weekly challenge deadline is due in a day or so (November 15, 2020). 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: Pair Differences

You are given an array of integers @N and an integer $A.

Write a script to find find if there exists a pair of elements in the array whose difference is $A.

Print 1 if exists otherwise 0.

Example 1:

Input: @N = (10, 8, 12, 15, 5) and $A = 7
Output: 1 as 15 - 8 = 7

Example 2:

Input: @N = (1, 5, 2, 9, 7) and $A = 6
Output: 1 as 7 - 1 = 6

Example 3:

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).



The Persuaders!

The Persuaders! is a particularly silly 1970s action TV series which lasted for only one season. Tony Curtis plays Danny Wilde to Roger Moore's Lord Brett Sinclair. Tony is the funny guy and Roger is the straight man. After the Persuaders, Roger Moore went on to become James Bond, and Tony Curtis went on to date Debee Ashby.

12d45aab-504d-4560-9a8b-a2d30c692f39.jpg

Although it wasn't a hit in America, The Persuaders actually became more popular in translation than in the original. One of the running gags is American Danny (Tony Curtis) making fun of snooty, toffee-nosed, upper-crust "your lordship" Roger Moore. But since the translated versions were for people who didn't know anything about British or American people, the translators invented new dialogue unrelated to the original, which ended up being more entertaining for the audience than the English dialogue. Which has nothing to do with Perl but here we go.

Is it possible to return to development with traditional P5P mailing lists?

Is it possible to return to development with traditional P5P mailing lists?

I still think the traditional method is suitable for advancing Perl development.

why?

We're used to it, and Perl development has been done that way.

We tend to think of it as a poor method, but it's actually a good one.

The first is that it will be developed with backward compatibility in mind.

The second is that we will not proceed unless there is a lot of consensus on the important points.

Some people say that Perl development can't proceed because of opposition.

I think there is no need to proceed with development with a lot of opposition.

I think it's important to find a way that as many people as possible can agree.

The culture of being able to decide everything because we have a majority is not good.

Make everything public and discuss about important decisions.

Small decisions are made by good P5P leaders.

On the other hand, big decisions will be disclosed and discussed to all users.

If the opposite happens, it's a normal reaction.

Is it possible to adjust features and modifications to the point where an agreement can be reached?

Is it possible to return to development with traditional P5P mailing lists?

Perl Podcasts

(Originally published on samirparikh.com.)

Like any well-entrenched programming language, Perl has a rich history and a number of personalities who shape and lead its community. In addition to wanting to learn its syntax and how to write simple scripts with it, I'm also trying to learn more about that history and the people who influence it today. I do this by following some blogs (which perhaps I'll write about later) and reading online books and articles but the best way for me is to listen to relevant podcasts. I'm an avid podcast listener and love learning about new concepts or technologies while walking the dog, doing the dishes, or pre-pandemic, sitting in traffic. Over the past few weeks, I've been listening to some contemporary as well as not so recent Perl-related podcasts and thought I'd share some select episodes that others may find interesting:

Perl Weekly Challenge 85: Triplet Sum and Power of Two Integers

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

Spoiler Alert: This weekly challenge deadline is due in a day or so (November 8, 2020). 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: Triplet Sum

You are given an array of real numbers greater than zero.

Write a script to find if there exists a triplet (a,b,c) such that 1 < a+b+c < 2. Print 1 if you succeed otherwise 0.

Example 1:

Input: @R = (1.2, 0.4, 0.1, 2.5)
Output: 1 as 1 < 1.2 + 0.4 + 0.1 < 2

Example 2:

Input: @R = (0.2, 1.5, 0.9, 1.1)
Output: 0

Example 3:

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:

Thank You, Coveralls.io

For letting me know my test coverage has increased by 0.00006%.

Coveralls.io screenshot

(Seriously it's a pretty cool service though.)

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.