Perl Weekly Challenge 48: Survivor and Palindrome Dates

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (February 23, 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: The Survivor

There are 50 people standing in a circle in positions 1 to 50. The person standing at position 1 has a sword. He kills the next person i.e. standing at position 2 and passes on the sword to the immediate next, i.e. person standing at position 3. Now the person at position 3 does the same and it goes on until only one survives.

Write a script to find out the survivor.

This is sometimes called the Josephus Problem, named after Flavius Josephus, a Jewish historian of the 1st century who allegedly escaped collective suicide of defeated Jewish soldiers trapped by Roman soldiers by finding the right position to be the survivor.

Some blogs.perl.org 10 Year Stats.

blogs.perl.org recently turned 10 years old. I was curious about the level of traffic so grabbed all of the post URLs and meta information to create the lists below. These are accurate up until the posting of this post (excluding this post):

  • Total Posts: 8,091
  • Total Posts (2016 Onwards): 2,595
  • Total Unique Authors: 676
  • Authors With Only 1 Post: 246

Most Active Authors (All Time):

  • byterock - 604
  • jt_smith - 442
  • ovid - 382
  • sawyer_x - 304
  • brian_d_foy - 227
  • steven_haryanto - 160
  • yuki_kimoto - 153
  • ron_savage - 148
  • joel_berger - 132

Most Active Authors (2016 onwards):

  • byterock - 417
  • sawyer_x - 138
  • yuki_kimoto - 93
  • dean - 72
  • mohammad_s_anwar - 69
  • melezhik - 66
  • zoffix_znet - 65
  • ovid - 59
  • neilb - 55

Most Active Months:

  • 2012-07: 163
  • 2010-08: 134
  • 2012-04: 128
  • 2011-10: 121
  • 2014-03: 121
  • 2013-02: 119
  • 2012-05: 118
  • 2012-03: 117
  • 2010-07: 114
  • 2011-11: 111

Total Post Count By Year:

  • 2009 - 116
  • 2010 - 1,023
  • 2011 - 1,094
  • 2012 - 1,274
  • 2013 - 1,006
  • 2014 - 983
  • 2015 - 542
  • 2016 - 535
  • 2017 - 459
  • 2018 - 664
  • 2019 - 395

Perl Subroutine Signatures Opinion Blog

I have great respect for Perl developers.

I am always grateful for the work.


On the other hand, I have a very strong concern in the future of Perl.


I created a site for my opinions on subroutine signatures so that themes would not be missed in the discussion.

Perl Subroutine Signatures Opinion Blog


I have no final authority. I pray Perl developers make a good decision.

Apache SpamAssassin 3.4.3 has been released!

Apache SpamAssassin 3.4.3 contains numerous tweaks and bug fixes as we prepare to move to version 4.0.0 with better, native UTF-8 handling. There are a number of functional patches, improvements as well as security reasons to upgrade to 3.4.3. In this release, there is also one new plugin and there are bug fixes for two CVEs:
  • CVE-2019-12420 for Multipart Denial of Service Vulnerability
  • CVE-2018-11805 for nefarious CF files can be configured to run system commands without any output or errors.
*** On March 1, 2020, we will stop publishing rulesets with SHA-1 signatures. If you do not update to 3.4.2 or later, you will be stuck at the last ruleset with SHA-1 signatures. ***

Download: https://spamassassin.apache.org/downloads.cgi?update=201912112330

See also https://spamassassin.apache.org/news.html

Perl Weekly Challenge 47: Roman Calculator and Gapful Numbers

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (February 9, 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 have really very little time to complete this blog post in time for the deadline. My explanations will be minimal, sorry about that.

Roman Calculator

Write a script that accepts two roman numbers and operation. It should then perform the operation on the give roman numbers and print the result.

For example,

perl ch-1.pl V + VI

It should print

XI

Paws XXXV (Well not a wrap but close)

Well it looks like a wrap for Paws S3

I made up my own test creation caller. No rocket science in this one. I just added in a few useful attributes;

Type::Tiny 1.8.0 released

Type::Tiny 1.8.0 (1.008000) was released today.

The new features are pretty minor. Most of the improvements are in documentation and testing.

  • Totally rewritten manual/tutorial.

  • Every issue on RT has been handled.

  • Bigger test suite. The exact number of tests run varies based on the availability of optional dependencies, but I just ran the test suite with EXTENDED_TESTING set to false and most of the optional dependencies installed, and it was nearly 7500 tests, compared to just over 2700 for Type::Tiny 1.6.0. With EXTENDED_TESTING true, there are nearly 13900 tests.

    This includes a set of tests for each built-in type which are intended to function both as test cases and advanced documentation.

Why is the specification of subroutine signatures so complicated?

As a general Perl user who uses Perl for text processing on Linux, I have a simple question.

Why is the specification of subroutine signatures so complicated?

Jumbo Signatures extensions discussion

The most common criticism of Perl is that it cannot read Perl grammar.

If Perl grammar evolves in an easy-to-understand direction, you are welcome.

If you are going to increase the complexity blame for Perl, think a little more.

Is this feature really useful for users who want to do text processing on Linux/Unix?

A single language cannot satisfy every need.

I have not yet seen what purpose Perl is aiming for.

Perl Weekly Challenge 46: Garbled Message and Room Open

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (February 9, 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.

Garbled Message

The communication system of an office is broken and message received are not completely reliable. To send message Hello, it ended up sending these following:

H x l 4 !
c e - l o
z e 6 l g
H W l v R
q 9 m # o

Similarly, another day we received a message repeatedly like below:

CPAN Testers at meta::hack v4

For this year's MetaCPAN Hackathon, I decided I wanted to start turning the CPAN Testers mockup I made 3 years ago into a real, working site. Along the way, I built a much better development environment for CPAN Testers, making it even easier for someone to start working on the project. I also released Mojolicious::Plugin::Moai, a UI widget kit for Mojolicious.

Thanks to cPanel and Booking.com for their continued sponsorship of this event!

Rewriting Perl Code for Raku IV: A New Hope

Part IV starts to get into the heart of OLE::Storage_Lite by covering the pack/unpack builtins.

Perl Weekly Challenge 037: Weekdays and Daylight Gain/Loss

Weekdays

Write a script to calculate the total number of weekdays (Mon-Fri) in each month of the year 2019.

I used the core module Time::Piece and its companion from the same distribution, Time::Seconds. Let’s start on the first day of the month, and keep adding one day while we stay in the same month. Along the way, count the days that aren’t Saturdays and Sundays.

Perl Weekly Challenge 45: Square Secret Code and Source Dumper

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

Task # 1: Square Secret Code

The square secret code mechanism first removes any space from the original message. Then it lays down the message in a row of 8 columns. The coded message is then obtained by reading down the columns going left to right.

For example, the message is “The quick brown fox jumps over the lazy dog”.

Then the message would be laid out as below:

thequick
brownfox
jumpsove
rthelazy
dog

The code message would be as below:

tbjrd hruto eomhg qwpe unsl ifoa covz kxey

Paws XXXIV (Yet more code)

Well after spending a little while trying to create an auto test generator I found the test generator script that came with PAWS.

So I decided to try it out. With only a little fudging of the code internals, no real code changes just changes to libs, I got it to work;

perl script/paws_make_testcase  S3 --region us-east-1 GetBucketLocation Bucket: "dev.cargotel.test"

the test file it generated /0001.response.test.yml;


--
tests:
  - expected: eu-west-2
    op: eq
    path: LocationConstraint

So that is ok.

However when I opened the caller file '0001.response' it contained only JSON;

Working with CSV files using PDL

Ahh, the venerable comma separated variable format, beloved of data scientists.

I grabbed a couple of csv files from Matt Pettis’ csvkit talk to prepare for the datafile that I should be getting my mitts on and tripped and bumped my way through the documentation for PDL::IO::CSV and metaphorically skinned my knees, as you do when you don’t read too carefully.

Constant Platypus

A common challenge in calling C functions from any language other than C or C++ is dealing with constants. In C these are usually implemented using #define pre-processor directives which are lost by the time the code is linked into a dynamic library. (In fact it is lost before the source is even compiled, since it is a pre-processor directive). For example, the libarchive library provides these constants in its header file for dealing with errors:

/*
 * Error codes: Use archive_errno() and archive_error_string()
 * to retrieve details.  Unless specified otherwise, all functions
 * that return 'int' use these codes.
 */
#define ARCHIVE_EOF       1     /* Found end of archive. */
#define ARCHIVE_OK        0     /* Operation was successful. */
#define ARCHIVE_RETRY   (-10)   /* Retry might succeed. */
#define ARCHIVE_WARN    (-20)   /* Partial success. */
/* For example, if write_header "fails", then you can't push data. */
#define ARCHIVE_FAILED  (-25)   /* Current operation cannot complete. */
/* But if write_header is "fatal," then this archive is dead and useless. */
#define ARCHIVE_FATAL   (-30)   /* No more operations are possible. */

Perl Weekly Challenge 44: Only 100, Please, and Make it $200

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

Challenge # 1: Only 100, Please

You are given a string “123456789”. Write a script that would insert ”+” or ”-” in between digits so that when you evaluate, the result should be 100.

Only 100, Please, in Perl

For solving this task, we first use a recursive combine subroutine that generates all possible strings by inserting between the digits of the “123456789” string the + plus addition, the - subtraction operator, or the '' empty string (i.e. no operator). We then use the evaluate subroutine with each string to perform the various arithmetic operations and compute whether the total is 100.

Paws XXXIII (A little advice please)

Well some-days it would be nice to get a little advice, without asking for it, before one heads down a very long and in the end futile path.

Today that happened to me when I was starting down a path that I dreaded. Namely creating the 'response' test suite for all those S3 requests I have fixed up over the past few weeks. This type of programming ranges from so mind numbingly dull as to cause your ears to bleed to so incredibility repetitive that you consider that career change to line supervisor at the box factory.

Looking at the prospect of coveting some 70+ working S3 units tests by hand was obviously getting me down a little. It took me a good three or four days of rather mindless hacking and re-running just to to the 'request' tests.

Rewriting Legacy Code in Raku III: The Sourceror

Part III in the series talks about functions, prototyping, and some of the tweaks you'll need to make while transferring Perl code to Raku

Perl Weekly Challenge 036: VIN Validation and the Knapsack Problem

VIN Validation

Write a program to validate given Vehicle Identification Number (VIN).

I followed the description at Wikipedia. Sometimes, it wasn’t exactly clear whether the described rule should be valid everywhere or just in a part of the world; the rules also developed with time, so older vehicles can bear VINs that would be considered invalid for a modern car.

Most of the validation is implemented in a single subroutine validate_vin. It takes two parameters, $vin and $sold: the second one says where the car was sold. "North America" and "China" are two values that trigger a different behaviour of the validator.

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.