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.
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):
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. ***
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.
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.
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:
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.
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”.
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.
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.*/
#defineARCHIVE_EOF1/* Found end of archive. */
#defineARCHIVE_OK0/* Operation was successful. */
#defineARCHIVE_RETRY (-10) /* Retry might succeed. */
#defineARCHIVE_WARN (-20) /* Partial success. *//* For example, if write_header "fails", then you can't push data. */
#defineARCHIVE_FAILED (-25) /* Current operation cannot complete. *//* But if write_header is "fatal," then this archive is dead and useless. */
#defineARCHIVE_FATAL (-30) /* No more operations are possible. */
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.
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.
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.