Spoiler Alert: This weekly challenge deadline is due in a few of days from now (on June 5, 2022 at 23:59). 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: Circular Primes
Write a script to find out first 10 circular primes having at least 3 digits (base 10).
A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its (base 10) digits will also be prime.
I recently got an Apple M1 Mac Mini, half out of curiosity, half because it was exactly what I would need: I have a low end Mac just to try out things like new Xcode betas etc, like a "canary" machine. My old 2012 Mac Mini stopped getting official Apple updates, so it could no longer do what I needed and the 8GB RAM, 256GB SSD M1 mini at $699 is easily the cheapest Mac you can buy.
Overall, unlike the typical Mac Minis of old which seemed to be on the slow side, it did feel quite fast from the start, so I thought I'd run some benchmarks on it for fun to see how Apple's ARM M1 fares against some x86 competition. And, as in my day job I use mostly Perl, I thought some perl-related benchmarks would be of interest to me.
On behalf of the Dancer Core Team, I'd like to announce the availability
of Dancer2 0.301002. This release includes a number of enhancements and
documentation changes along with several bugfixes. The most notable
enhancement is a brand new command line interface, and I highly
encourage you to check it out.
The current Yet Another Society (The Perl Foundation) bylaws exclude the possibility of membership (see Article II https://www.perlfoundation.org/bylaws.html). As reference, the Python Foundation has 5 membership classes with various rights and privileges associated (https://www.python.org/psf/bylaws/).
I believe this to be a wasted opportunity to increase engagement with stake holders in the Perl community, be they individuals, business or other organizations. And also to secure funding for vital Perl related activities arranged by the Perl Foundation.
Rather than a complicated class system,a good starting point would be a single membership option with an annual renewal and no specific benefits than a warm feeling. (Although, throwing in some exclusive swag and a membership card might not be a bad little bonus)
This could then evolve based on feedback via a membership committee.
I have sent a brief proposal to the YAS (TPF) board to this effect. I invite your support in comments below and/or by contacting board members voicing your support (see https://www.perlfoundation.org/committees.html)
As an old systems programmer, whenever I needed to come up with a 32-bit number, I would reach for the tired old examples like 0xDeadBeef and 0xC0dedBad. I want more!
Write a program that will read from a dictionary and find 2- to 8-letter words that can be “spelled” in hexadecimal, with the addition of the following letter substitutions:
o ⟶ 0 (e.g., 0xf00d = “food”)
l ⟶ 1
i ⟶ 1
s ⟶ 5
t ⟶ 7
You can use your own dictionary or you can simply open ../../../data/dictionary.txt (relative to your script’s location in our GitHub repository) to access the dictionary of common words from Week #161.
Optional Extras (for an 0xAddedFee, of course!
* Limit the number of “special” letter substitutions in any one result to keep that result at least somewhat comprehensible. (0x51105010 is an actual example from my sample solution you may wish to avoid!)*
Presently I have great interest in “EVs” Electric Vehicles but I haven’t seen any data on how much it would cost to charge an electric vehicle from 0 % to 100 % battery charge at home in NYC ( So I wrote a Perl script to do just that ) but before we dig in into it I explain a few things about Electric Vehicles.
Electric Vehicles will have a battery capacity that is represented by kilowatt-hour units or kWh for short.
An EV’s driving range is represented in miles units ( In the US ) and the average mileage is determined by the EPA battery range rating ( the bigger the battery capacity usually means the more driving range you will have in a car ) after conducting a few tests ( so in reality your mileage will vary ).
Kent was a prolific contributor to CPAN and Perl.
He released more than 150 distributions of his own to CPAN,
but also helped countless other authors and distributions,
with bug reports, puil requests, and more.
When a CPAN author dies,
their indexing permissions are dropped from PAUSE,
and where they had the first-come permission,
that will be passed to the pseudo-user ADOPTME.
This flags the distribution as being available for adoption.
So as of now, all of Kent's distributions are available for adoption.
This week, Task 1 and part of Task 2 relate to Scalable Vector Graphics (SVG). I’d been using SVG a very long time ago and certainly didn’t remember any of the details. So, in my first blog relating to PWC 165, I stated that I didn’t have time for that and covered only the part of the challenge not related to SVG. I also said that, in the event that I find some time over the weekend, I might come back and fulfill the SVG part. I thought at the time that this was rather unlikely, but I was finally able to cover the SVG part, at least in Raku.
and so on at the top of each script they write. For scripts which I don't intend to publish anywhere, I have a module (which I accidentally called Z not knowing there was already a module of the same name on CPAN), which switches on lots of things at once just by saying
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).
-------------------------------------
My coding momentum is a bit low.
Reflections on the codes I have written:
#095
Task 1: Palindrome Number
TMTOWTDI. On this seemly and actually simple task, I chose to compare the digit one by one.
Task 2: Demo Stack
A bit smell of laziness. I did not provide functions when stack is empty and pop() or min() is called.
#096
Task 1: Reverse Words
A lesson on extra-white space. Oppositely but as lack of caution as a sin, this morning (GMT+8) I found I have forgotten a newline for my code for #105 Task 1.
Task 2: Edit Distance
That was a standard computer science exercise. I was astounded by reading Mr Abigail's blog on the approach on saving memory space.
During the last years it became fashionable to rag on object oriented programming and a decade ago I would join the choir. Hack, when I started with Perl I despised the bloat and inefficiency of many corporate smelling *coughjava* systems and preached the light weight and foreward thinking way that real hackers travel. In this miniseries I want to write why I changed my tune [part one], the best way (IMO) to use OOP [part two] and why inheritance (incl. roles and templates) and delegation or not helpful features (in contrast to polymorphism) [part three]. Maybe there will be more about rating Perl OO features and modules.
Spoiler Alert: This weekly challenge deadline is due in a few of days from now (on May 22, 2022 at 24:00). This blog post offers some (partial) solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.
I decided that I would not go the easy way this week and just use the power function ** i.e. return $k**(1/$N).
Instead for integer values of $N, solve this with only using the simple mathematical operators +, /, *, -, <, >
To do this we will use a divide and conquer solution, starting at the two ends of the interval we calculate the values of x^N, and then iterate reducing the interval in half - choosing the interval where the value of x^N is less than k at the left hand end & x^N is greater than k.
To do this we store the value of the ends of the interval as l and r respectively and computer the Nth power of each (ln & rn).
If you’ve read Curtis “Ovid” Poe’s articles on the declarative framework for Tau Station Link and Link, you are undoubtedly aware of many of the benefits this style of programming can bring. It decouples the “what” from the “how”, encourages discrete functions and prevents the OO trap of “god objects”. The result is software that is easy to test, robust and very flexible. Inserting steps, reording steps etc… are done much easier and more clearly than trying to figure this out in 300 lines of imperative code with four to six level deep if-else chains with for loops mixed in for good fun. However, the framework is tightly coupled to the game in spots and has a few other issues that make it not ready for general use.
I've been asked by a couple of Perl groups to give a virtual presentation. Writing new material that would only have been shown once is a lot of work for a small reward.
But, I just happened to be cleaning out my virtual junk drawer, and stumbled across my "half my life with Perl" slide deck that I had presented at OSCON 2013. Most of the stuff is timeless, as it describes Perl's first 25 years, and my second 25 years and how I influenced Perl, and Perl influenced me, and how my company (Stonehenge) was changed by all of this, and in some ways even changed all of this as well.
Please tune in at 6pm Pacific Time (currently UTC-7) on Monday the 22nd to watch it live. I will try to read the comments quickly at the end of the show and answer any questions as well. The video will remain permanently on Youtube at the address below.
Live link: https://www.youtube.com/watch?v=8VMz7GINc2E
Spoiler Alert: This weekly challenge deadline is due in a few of days from now (on May 15, 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: Prime Palindromes
Write a script to find all prime numbers less than 1000, which are also palindromes in base 10. Palindromic numbers are numbers whose digits are the same in reverse. For example, 313 is a palindromic prime, but 337 is not, even though 733 (337 reversed) is also prime.
Prime Palindromes in Raku
We use a data pipeline (chained method invocations) with two grep statements, one to keep palindromes and one to keep prime numbers. This leads to a fairly concise one-line solution:
say (1..^1000).grep({ $_ == .flip }).grep({.is-prime});
Let's examine if in 2021 an email redistribution list, i.e. perl5-porters@ (p5p) is still the best model for collaborating on the perl language. This is a discussion so comment below!
Advantages of an email list:
Familiar interface, people can use their client of choice
Low resources to run and maintain
Easy to derive automation from as email is all well known protocols
Everything is email
Disadvantages of an email list:
Email addresses disclosed to all participants (can be changed)
UI experience for participants inconsistent, may require client side configuration to "get right"
Email "reply" text can lower the signal to noise ratio
No topic categorization of posts, its all dumped in to your inbox
Tricky to respond to missed emails
Moderation is crude, every email is reviewed and approved, or everything is approved
Once an email is relayed it can't be moderated further
Encourages side channel correspondence
Everything is email
Given the long list of disadvantages we can guess why email lists (and newsgroups) have largely fallen by the wayside.
Write a script to generate first 50 members of FUSC Sequence. Please refer to OEIS for more information.
The sequence defined as below:
fusc(0) = 0
fusc(1) = 1
for n > 1:
when n is even: fusc(n) = fusc(n / 2),
when n is odd: fusc(n) = fusc((n-1)/2) + fusc((n+1)/2)
Solution
I will show you 4 versions of the code below - they essentially non-cached/cached versions of recursive (naive) code to get an individual element, and a non-recursive version to compute the whole sequence.
On behalf of the Dancer Core Team, version 0.301000 is now available. This is not the release we envisioned; it is missing some things we'd like to have finished, but it does have a couple of new things worth pointing out:
A new keyword, request_data, to get the entire deserialized body of the request
A new Cookbook recipe for showing how to dynamically enable/disable modules and routes at runtime
Numerous doc and bug fixes.
Check out the changelog for a complete list of changes.
The big thing worth pointing out is App::Cmd, which is now not a requirement of Dancer2. A new version of App::Cmd was released with a minimum version requirement of Perl 5.20. We aim to support Dancer2 back to Perl 5.10, which was no longer possible with the current App::Cmd. We had several options to consider in moving forward, and the one we chose was this: