aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-08-03 23:16:03 +0100
committerGitHub <noreply@github.com>2025-08-03 23:16:03 +0100
commitd3d30ff167d26fb891a737d9579dd36d85e15c30 (patch)
tree01383a874c3524f01c809df7209ec40fd129f886
parent9ea250a98e1d7ac0c1b2e05608bcbd59776e43b1 (diff)
parent1b73ab6159d7aca6984477dcaea5b065adde7aae (diff)
downloadperlweeklychallenge-club-d3d30ff167d26fb891a737d9579dd36d85e15c30.tar.gz
perlweeklychallenge-club-d3d30ff167d26fb891a737d9579dd36d85e15c30.tar.bz2
perlweeklychallenge-club-d3d30ff167d26fb891a737d9579dd36d85e15c30.zip
Merge pull request #12454 from mattneleigh/pwc332
new file: challenge-332/mattneleigh/perl/ch-1.pl
-rwxr-xr-xchallenge-332/mattneleigh/perl/ch-1.pl57
-rwxr-xr-xchallenge-332/mattneleigh/perl/ch-2.pl70
2 files changed, 127 insertions, 0 deletions
diff --git a/challenge-332/mattneleigh/perl/ch-1.pl b/challenge-332/mattneleigh/perl/ch-1.pl
new file mode 100755
index 0000000000..12559353ab
--- /dev/null
+++ b/challenge-332/mattneleigh/perl/ch-1.pl
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use English;
+
+################################################################################
+# Begin main execution
+################################################################################
+
+my @dates = (
+ "2025-07-26",
+ "2000-02-02",
+ "2024-12-31"
+);
+
+print("\n");
+foreach my $date (@dates){
+ printf(
+ "Input: \$date = \"%s\"\nOutput: \"%s\"\n\n",
+ $date,
+ date_to_binary($date)
+ );
+}
+
+exit(0);
+################################################################################
+# End main execution; subroutines follow
+################################################################################
+
+
+
+################################################################################
+# Convert a date in YYYY-MM-DD format to an equivalent binary representation in
+# which the year, month, and day have all been converted to a binary
+# representation consisting of ones and zeros
+# Takes one argument:
+# * A string containing the date to convert (e.g. "2025-07-26")
+# Returns:
+# * A string containing the supplied date represented in binary as a series of
+# ones and zeros (e.g. "11111101001-111-11010")
+################################################################################
+sub date_to_binary{
+
+ # Split the date into numbers, process them into binary,
+ # recombine them into a new date, and return
+ return(
+ sprintf(
+ "%b-%b-%b",
+ split(/-/, shift())
+ )
+ );
+
+}
+
+
+
diff --git a/challenge-332/mattneleigh/perl/ch-2.pl b/challenge-332/mattneleigh/perl/ch-2.pl
new file mode 100755
index 0000000000..8b2fed971d
--- /dev/null
+++ b/challenge-332/mattneleigh/perl/ch-2.pl
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use English;
+
+################################################################################
+# Begin main execution
+################################################################################
+
+my @words = (
+ "weekly",
+ "perl",
+ "challenge"
+);
+
+print("\n");
+foreach my $word (@words){
+ printf(
+ "Input: \$str = \"%s\"\nOutput: %s\n\n",
+ $word,
+ all_letters_odd($word) ? "true" : "false"
+ );
+}
+
+exit(0);
+################################################################################
+# End main execution; subroutines follow
+################################################################################
+
+
+
+################################################################################
+# Determine whether each of the letters within a string occurs an odd number of
+# times
+# Takes one argument:
+# * The string to examine (e.g. "Perl")
+# Returns:
+# * 0 if there is at least one letter that appears an even number of times
+# * 1 if all letters appear an odd number of times (as would be the case in the
+# example above)
+# NOTE: Non-letter characters are ignored; letter counting is case-insensitive-
+# 'P' and 'p' are the same for counting purposes
+################################################################################
+sub all_letters_odd{
+
+ my %letter_bits;
+ my $letter;
+
+ # Toggle an 0x01 bit for each letter in the supplied
+ # string; if the final value for a letter is 0, that
+ # letter appeared an even number of times
+ foreach $letter (grep(/[a-z]/, split("", lc(shift())))){
+ $letter_bits{$letter} ^= 0x01;
+ }
+
+ # See if there are any zeros among the values computed
+ # for each letter; if so, a letter appeared an even
+ # number of times
+ if(grep(!$_, values(%letter_bits))){
+ return(0);
+ }
+
+ # No even counts were found- return 1
+ return(1);
+
+}
+
+
+