You are given an array representing box coins, @box.
Write a script to collect the maximum coins until you took out all boxes. If we pick box[i] then we collect the coins $box[i-1] * $box[i] * $box[i+1]. If $box[i+1] or $box[i-1] is out of bound then treat it as 1 coin.
Example 1:
Input: @box = (3, 1, 5, 8)
Output: 167
Step 1: pick box [i=1] and collected coins 3 * 1 * 5 => 15. Boxes available (3, 5, 8).
Step 2: pick box [i=1] and collected coins 3 * 5 * 8 => 120. Boxes available (3, 8).
Step 3: pick box [i=0] and collected coins 1 * 3 * 8 => 24. Boxes available (8).
Step 4: pick box [i=0] and collected coins 1 * 8 * 1 => 8. No more box available.
Following from my previous post, I am now actively encouraging everyone to switch licenses to MIT/ISC license or Apache 2.0.
My reasoning is that in the vast majority of cases the author and contributors want the software to be used by as many businesses and hobbyists as possible.
Previously I described how the burden of understanding and complying with licenses, including open source licenses, can be an unintended barrier to them using the software.
Perl modules tend to use "Perl 5" combination as the default license i.e. "Licensed under the same terms as Perl itself". And the "Perl 5" license is actually a dual licensing of the problematic Artistic 1.0 license and the dated GPL1.0 license which also has problems. Both are rarely used outside of Perl and in my view present a barrier to adoption.
Recall I described how permissive ("BSD") and copyleft ("GPL") licenses are functionally identical if no binary is distributed (websites) or for scripted languages that remain in source form.
Hello ,
When "use DateTime;" library is included in perl file ,getting the error as
"CPM0 frl-plugin:perlscript: ERROR: 'times' trapped by operation mask at /usr/lib64/perl5/B.pm line 183."
Could someone provide some inputs on the same.
Also to which tag does this opcode 'times' belong to ?
example: fork,wait, waitpid will belong to :subprocess
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on July 2, 2023 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: Count Primes
You are given a positive integer, $n.
Write a script to find the total count of primes less than or equal to the given integer.
Example 1
Input: $n = 10
Output: 4
Since there are 4 primes (2,3,5,7) less than or equal to 10.
Revision: that Cincinnati Perl Mongers found an error in the benchmark script used for this post. Match Anything Quickly - Revision 1 discusses their findings and links to a revised benchmark script. -- TRW 2022-09-02
Sometimes I want to filter a set of strings, but the details of the filter are not known beforehand. In particular, I may want a null filter, which simply accepts anything.
This looks like a job for a regular expression, but I can think of at least two implementations. One is to pass around regular expression objects. The second is to wrap a match (m//) in a subroutine reference, and pass that around. Given the use of regular expressions, there are a number of possibilities for a regular expression that matches any string.
I will get it wrong. I will start off by saying that, not just because I am married and this sentiment has been conjugally programmed in me for years, but because doing things "my way" will not suit everybody. We approach life, programming, drawing from different perspectives, different analogies, and one method however disagreeable to one person, may be perfectly logical to another. Even our own actions and analysis show conflicts. Take a cup of tea. I drink from the top of the cup, but measure from the bottom. Take character position in programming code...we measure lines from the top, then character on that line. But when we write, we write one line at a time, populating columns in a line before going to the next line.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on June 25, 2023 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: Matching Members
You are given a list of positive integers, @ints.
Write a script to find the total matching members after sorting the list increasing order.
In the year 2000, the world was a different place. Y2K was still fresh in our memories, many of us had just partied like it was 1999 and Mark Fowler had given up eating chocolate.
Hurray, released another version of Chart without new features. Actually rewrote the complete documentation and I guess especially this page (with a little help of this list) is all what most people need. That also allowed us to drop the old PDF and HTML docs which took 8/9 of the distributions space (good side effect).
But main reason to tell this: writing the docs forced me to plough through most of code and also test most of it with self written or at least adapted code, which brought me into the position actually understand what I maintain.
So now I can give actually intelligent responses to feature requests. So please post them here or there. And yes , there will be SVG support, but not soon.
The Perl sort built-in is mostly (at least by me) called as sort LIST or sort BLOCK LIST. But there is a third way to call it: sort SUBROUTINE LIST, which actually appears first in the documentation.
This is not a blog entry about using the sort SUBROUTINE LIST form of sort. It is more about the need to be aware of this form when writing (or trying to write) the sort LIST form.
Consider the following situation: you have a subroutine foo() which returns an un-ordered list. You need that list sorted. Perl has a sort built-in, so your (or at least my) first reaction is to write my @sorted = sort foo();, run it, and then wonder why @sorted is empty.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on June 18, 2023 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.
Arithmetic Subsequence
You are given an array of integers, @ints.
Write a script to find the length of the longest Arithmetic Subsequence in the given array.
A subsequence is an array that can be derived from another array by deleting some or none elements without changing the order of the remaining elements.
A subsequence is arithmetic if ints[i + 1] - ints[i] are all the same value (for 0 <= i < ints.length - 1).
So why not a generalized interface to Bug, Task, and Issue trackers? And an accompanying cli tool?
Jira is obviously very common for organizations to use, Github issues are ubiquitous, Bugzilla is still around, Request Tracker has a strong following, not to mention Zendesk, OTRS, and so many others you're forced to use each day for your work. Likely your organization or employer uses more than one!
Having a generalized interface makes automation interactions more trivial and vastly more consistent. With this interface established, an accompanying command line tool becomes a logical addition. And if you aren't yet automating interactions with your Bug / Task / Issue tracker, then having an interface is even more important to getting you started.
Such an interface would be the majority of whats needed for a unified interface and cli tool and to interact with CPAN modules bugs/issues regardless if they are on Github, RT, or other. Something similar to Debian's reportbug command.
I wrote this post after seeing Flavio Poletti's blog post entitled
OATH Toolkit.
I have been a fan of time-based one time passwords (TOTP) for many years.
In fact, I used Mobile-OTP in commercial
applications for several years before the
Initiative for Open Authentication (OATH)
and OATH/TOTP were codified in
RFC6238.
Now-a-days, OATH/TOTP is the best choice for time-based one time passwords,
and has been for at least a decade.
Introduction
I have implemented OATH/TOTP many times in my career, and in several programming
languages, including Perl. One of those Perl implementations is within the
open source program kpcli.
Using Authen::OATH for TOTP
Using Authen::OATH for TOTP is straightforward. The kpcli code
appears a little overly complex because it optionally demand-loads the
Authen::OATH module and has support for digest ciphers other than
SHA1. This is kpcli's get_totp() subroutine:
This policy is assigned to the 'bugs' theme. It has low severity because there are some uses of these operators that seem legitimate to me -- or at least I see no easy way to get around their use.
On the one hand, something like
-r $file or die "File $file not readable\n";
open my $handle, '<', $file;
is wrong several ways. On the other hand, it is hard to see how to implement File::Which without the use of -x. And in fact it does use -x.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on June 18, 2023 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.
Good Strings
You are given a list of @words and a string $chars.
A string is good if it can be formed by characters from $chars, each character can be used only once.
Write a script to return the sum of lengths of all good strings in words.
Example 1
Input: @words = ("cat", "bt", "hat", "tree")
$chars = "atach"
Output: 6`
The good strings that can be formed are "cat" and "hat" so the answer is 3 + 3 = 6.
Hello All,
Facing flock error when trying to execute the Automated unit testing .
705:041754.467 CPM0 frl-plugin:perlscript: ERROR: 'flock' trapped by operation mask at /usr/lib64/perl5/vendor_perl/Storable.pm line 268.
Compilation failed in require at /usr/share/perl5/vendor_perl/Const/Fast.pm line 15.
Compilation failed in require.
BEGIN failed--compilation aborted.
I had a great time hacking on the Perl Navigator and Raku Navigator as part of the Perl IDE Hackathon 2022. Thank you to everyone who volunteered their time in person or remotely. Thanks especially to Brian for having many github issues ready for people to work on, and for helping so many people understand the concepts of Language Servers. I received compliments that the Hackathon was very organized but truthfully if people got that impression then Brian should get all the credit!
As a community I feel we could do better at helping people getting started and involved, so my goal was to emphasize first time and one off contributions. Brian caught the vision on this and as mentioned, did a great job preparing github issues and spent much of his time getting peoples development environment running. Hopefully he will post a report on what got done in the near future.
I have always understood that variables whose names begin with anything but an alphabetic or an underscore are reserved to Perl, and you mess with them at your peril. And this is the gist of the Porters' response to the post. Recent versions of perlvar say this explicitly, though earlier versions of that document restrict themselves to describing currently-implemented special variables.
For what it's worth, perl532delta appears not to mention this as a new diagnostic.
I wondered how much of this kind of thing was in CPAN, so I whipped up a Perl::Critic policy to try to find them: Variables::ProhibitNumericNamesWithLeadingZero. I then ran this against CPAN as it stood July 23 2022.