Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #376 (“Chessboard Squares” and “Doubled Words”)
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, with a new pair of tasks each Monday. You can find it here: The Weekly Challenge
The Weekly Challenge for the week of 2026-06-01 through 2026-06-07 is #376. The tasks for challenge #376 are as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 376-1: Chessboard Squares Submitted by: Mohammad Sajid Anwar Write a script to determine if two chess-board squares (specified by standard chess notation) have the same color.
To solve this problem, I query whether the sum of the first coordinate pair and the sum of the second coordinate pair have the same modulo 2.
Robbie Hatley's Perl Solution to The Weekly Challenge 376-1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 376-2: Doubled Words
Submitted by: Matt Martini
You are given a string (which may contain embedded newlines)
which is taken from a page on a website. The string will not
contain brackets qw{ [ ] }. Write a script that will find
doubled words (such as “this this”) and highlight (wrap in
brackets) each doubled word. The script should:
- Work across lines, even finding situations where a word at the
end of one line is repeated at the beginning of the next.
- Find doubled words despite capitalization differences, such as
with 'The the...', as well as allow differing amounts of
whitespace (spaces, tabs, newlines, and the like) to lie
between the words.
- Find doubled words even when separated by HTML tags. For example, to
make a word bold: '...it is <B>very</B> very important...'.
- Only show lines containing doubled words.
Adapted from Mastering Regular Expressions, Third Edition,
by Jeffrey E. F. Friedl.
The bulk of this task can be done with a single regular expression.
Robbie Hatley's Perl Solution to The Weekly Challenge 376-2
That's it for challenge 376; see you on challenge 377!
Comments
Post a Comment