Perl Weekly Challenge 109: Chowla Numbers and Four Square Puzzle

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

Spoiler Alert: This weekly challenge deadline is due in a few days (April 25, 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.

Task 1: Chowla Numbers

Write a script to generate first 20 Chowla Numbers, named after, Sarvadaman D. S. Chowla, a London born Indian American mathematician. It is defined as:

C(n) = sum of divisors of n except 1 and n

Output:

0, 0, 0, 2, 0, 5, 0, 6, 3, 7, 0, 15, 0, 9, 8, 14, 0, 20, 0, 21

Originally, the task requested us to generate the first 37 Chowla numbers and I wrote implementations in 12 different languages based on that requirement. This requirement has now been amended to the first 20 Chowla numbers. I’ll fix the program and output for some implementations, but will leave some as they were developed.

Chowla Numbers in Raku

BLOG: The Weekly Challenge #063

https://perlweeklychallenge.org/blog/weekly-challenge-063

Late May Software Releases

There have been several! LANraragi, ZEVENET CE, LedgerSMB, and Sympa. All great perl software!

LANraragi v.0.7.0 -- Cat People (Putting Out Fire)

Web application for archival and reading of manga/doujinshi. Lightweight and Docker-ready for NAS/servers.

This release includes an API revamp, categories have finally been added, PDF files are now first class citizens, Docker image is much smaller, and many other fixes and small features.

Check it out here: https://github.com/Difegue/LANraragi/releases/tag/v.0.7.0


ZEVENET Community Edition v5.11.1

The community edition of this load balancer appliance is bugfixes.

Check it out at: https://github.com/zevenet/zlb/releases/tag/v5.11.1


LedgerSMB 1.7.14

This accounting software's release is composed primarily of bugfixes.

Check it out at: https://github.com/ledgersmb/LedgerSMB/releases/tag/1.7.14

Sympa 6.2.56

This release is a all bugfixes for this mailing list management software

Check it out at: https://github.com/sympa-community/sympa/blob/6.2.56/NEWS.md

Perl Weekly Challenge 061: Product SubArray And IPv4 Partition

Product SubArray

Given a list of 4 or more numbers, write a script to find the contiguous sublist that has the maximum product. The length of the sublist is irrelevant; your job is to maximize the product.

Example

Input: [ 2, 5, -1, 3 ]

Output: [ 2, 5 ] which gives maximum product 10.

The easiest (but probably not the fastest) method would be to start from each position and compute the products of all the possible sublists starting at the position, remembering the positions where the product is maximal.

I automatically reached for List::Util’s product to get the products easily, but alas! Running

product(-1, 3)

caused a Floating point exception (bug reported). So, I had to implement product myself:

Perl Weekly Challenge 108: Locate Memory and Bell Numbers

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

Spoiler Alert: This weekly challenge deadline is due in a few days (April 18, 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.

Task 1: Locate Memory

Write a script to declare a variable or constant and print it’s location in the memory.

Locate Memory in Raku

Vikna: pre-release of a text console UI framework for Raku

After almost half a year of work I finally publish my new project Vikna which is also the subject of my talk at the upcoming Conference in the Cloud.

As the subject says, it is a clear pre-release and a proof of concept for the preview of those who might be interested. In the project I tried to get hold of all the best what Raku can offer in the field of asynchronous/threaded processing and OO. Whish you can as much fun trying it as I have in developing!

BLOG: The Weekly Challenge #061

https://perlweeklychallenge.org/blog/weekly-challenge-061

Sqitch v1.1.0 released

Sqitch is a database change management application. It currently supports PostgreSQL 8.4+, SQLite 3.7.11+, MySQL 5.0+, Oracle 10g+, Firebird 2.0+, Vertica 6.0+, Exasol 6.0+ and Snowflake.

Changelog at https://github.com/sqitchers/sqitch/releases/tag/v1.1.0

Perl Weekly Challenge 107: Self-Descripting Numbers and List Methods

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

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

Self-Descriptive Numbers

Write a script to display the first three self-descriptive numbers. As per Wikipedia, the definition of Self-descriptive Number is:

In mathematics, a self-descriptive number is an integer m that in a given base b is b digits long in which each digit d at position n (the most significant digit being at position 0 and the least significant at position b−1) counts how many instances of digit n are in m.

For example, 1210 is a four-digit self-descriptive number:

PWC 060: Task #1, Excel Column & Task #2, Find Numbers

PWC Task #1, Excel Column

jaredor submission for Task #1

Convert back and forth between base 10 and base 26, no problem.

"Column A" equals 1? Problem.

Okay, as problems go, that is a small one. Let I, an old Fortran programmer who loves perl, be your guide between offset indexing and ordinal indexing. First of all, we should complete our assessment of the lay of the land:

"Column 1" equals 1? Problem.

Yes, both column numbering systems start at "one", not "zero", but the mechanical conversion between number bases requires modular arithmetic, which is very much related to offset (0-based) indexing.

Note the quotes? They are meant to emphasize the concept of "one-ness" and "zero-ness" so that I don't have to deal with lexicographic tautologists telling me that "A is A, 1 is 1." Work with me here: The core of difficulty in this task is that we are translating between two number systems that don't have a zero and zero is a big thing.

BLOG: The Weekly Challenge #060

https://perlweeklychallenge.org/blog/weekly-challenge-060

CY's Post on PWC#060: Numbers with Headache

This is a part of Perl Weekly Challenge(PWC) #060 and the followings are related to my solution. If you want to challenge yourself on Perl, go to https://perlweeklychallenge.org, code the latest challenges, submit codes on-time (by GitHub or email) if possible, before reading my blog post

Do tell me if I am wrong or you strongly oppose my statements!

Task #1: Excel Column

Firstly we observe that 16384 < 263 = 17576 . Therefore there are at most 3 alphabets for the spreedsheet nomenclature. Knowing the cases to handle are not massive, I handle the cases with some subroutines named AtoOne, AtoZero and OnetoA.

The in-production testing line is for (1..3000) {print (numtoExcelCol($_),"\n"} and the finalized testing line is     for (1..$MAX) {print($_,"\n") unless $_ == excelcoltoNum(numtoExcelCol($_));} .


Task #2 Find Numbers

The original task makes me feel it is an exercise for using the module Math::Combinatorics .

Afterall, hence I modify the following more mathematically interesting task for myself:

Perl Weekly Challenge 106: Maximum Gap and Decimal String

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

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

Task 1: Maximum Gap

You are given an array of integers @N.

Write a script to display the maximum difference between two successive elements once the array is sorted.

If the array contains only 1 element then display 0.

Example:

Paging for Fun and Profit

Paging PAWS for fun an profit


Egad have been away for a while, it is not due to laziness on my part, I really have been stuck on a Paws problem over the past month+, add to that dozens of inside and out sided projects that I need to get done around the house time has just not been there.

At least I have finally cracked it.

I really went down a rabbit hole for this one and spend way too many hours trying to figure out how to test 'Paws Pagination' end to end.

In my last post I started out with a new test suite '30_pagination.t' and a few test YAMLs.

Just getting the YAML just right took God only knows how many iterations. I also had to create a completely new caller 'TestPaginationCaller.pm' to get the tests to work.

Perl Weekly Challenge 060: Excel Column And Find Numbers

Excel Column

Write a script that accepts a number and returns the Excel Column Name it represents and vice-versa.

Excel columns start at A and increase lexicographically using the 26 letters of the English alphabet, A..Z. After Z, the columns pick up an extra “digit”, going from AA, AB, etc., which could (in theory) continue to an arbitrary number of digits. In practice, Excel sheets are limited to 16,384 columns.

Example

Input Number: 28
Output: AB

Input Column Name: AD
Output: 30

This seemed like a simple base 10 to base 26 conversion and back. I started by installing Math::Base::Convert, Math::BaseConvert, Math::BaseCnv, and Convert::AnyBase to quickly discover they wouldn’t help me much. What Excel uses for column names is a weird 26 digit system that lacks a symbol for zero, but has a symbol for 26 (or for 1026). It’s called the bijective base-26 numeration system. The interesting fact about such systems is that digit addition, subtraction, and multiplication work the same way as in our common system (division is a bit problematic).

BLOG: The Weekly Challenge #059

https://perlweeklychallenge.org/blog/weekly-challenge-059

Perl Weekly Challenge 105: Nth Root and The Name Game

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

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

Task 1: Nth Root

You are given positive numbers $N and $k.

Write a script to find out the $Nth root of $k. For more information, please take a look at the wiki page.

Example:

Input: $N = 5, $k = 248832
Output: 12

Input: $N = 5, $k = 34
Output: 2.02

PWC 059: Task #1, Linked List & Task #2, Bit Sum

PWC Task #1, Linked List

jaredor submission for Task #1

Partitioning an input array into a @lower and @upper array based on a pivot element, $k, and then recombining into an output array (@lower, @upper) is pretty easy, e.g.,

say join(' ', (grep { $_ < $k } @ARGV), (grep { $k <= $_ } @ARGV));

A linked list can be collapsed into an array easily enough, so the challenge here (for me) is to add a little extra in the handling that could be useful in the future (because I always steal from myself ;-)

So maybe the little extra is this: Once a link is made it won't be copied.

I started explaining everything and it started feeling like I was writing a very boring novel. Below I'll just stick to the link logic.

Details

Input

There is one command line option:

--k
Specify the pivot point, k, per the problem instructions. [REQUIRED]

The arguments are the elements of the chain, in order, from HEAD to TAIL, since I like to make things as easy for myself as possible.

Link Logic

CY's take on Perl Weekly Challenge #059

linked_item.png

This is a part of Perl Weekly Challenge(PWC) #059 and the followings are related to my solution. If you want to challenge yourself on Perl, go to https://perlweeklychallenge.org, code the latest challenges, submit codes on-time (by GitHub or email) if possible, before reading my blog post.

(Finally, I installed a Linux distribution in my laptop -- my choice is Linux Mint (a distribution forked from earlier Ubuntu) .) (In Hong Kong, there are no shops selling Linux-installed/Linux-Windows-dual-boot laptop. People[1] are too rich and just buy Windows pre-installed laptops or MacBooks.(???) ) (This is not my first time to own a laptop with Linux but this time I am more serious about the system setting.)

The COVID-19 virus pandemic is under control in Hong Kong these two week. What a piece of good news.

Perl Weekly Challenge #058

Monthly Report - May

I have been doing Monthly Report since June 2018 non-stop. It has become a ritual for me now. It gives me an opportunity to look upon my activities. Since the beginning of the year 2020, I have made conscious decision to slow down as far as submitting Pull Request. I have also stopped playing CPAN game of daily upload after breaking the chain three times. I am happy that Perlancar is keeping the game alive. It has given me space to try something new. Although COVID-19 keeping us indoor all the time, still looking for interesting project to keep the mind busy.

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.