aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Green <mail@simon.green>2025-08-03 17:54:51 +1000
committerSimon Green <mail@simon.green>2025-08-03 17:54:51 +1000
commit39d8e45fc8a55d48a2b5bbceef09d7a2de1d846e (patch)
tree01264677624c449a5e65dcd01bf7347d4fd82d0d
parent6f0d16f05f2773a17829abb2db30dff2c2f73444 (diff)
downloadperlweeklychallenge-club-39d8e45fc8a55d48a2b5bbceef09d7a2de1d846e.tar.gz
perlweeklychallenge-club-39d8e45fc8a55d48a2b5bbceef09d7a2de1d846e.tar.bz2
perlweeklychallenge-club-39d8e45fc8a55d48a2b5bbceef09d7a2de1d846e.zip
sgreen solutions to challenge 332
-rw-r--r--challenge-332/sgreen/README.md4
-rw-r--r--challenge-332/sgreen/blog.txt1
-rwxr-xr-xchallenge-332/sgreen/perl/ch-1.pl19
-rwxr-xr-xchallenge-332/sgreen/perl/ch-2.pl20
-rwxr-xr-xchallenge-332/sgreen/python/ch-1.py32
-rwxr-xr-xchallenge-332/sgreen/python/ch-2.py27
-rwxr-xr-xchallenge-332/sgreen/python/test.py30
7 files changed, 131 insertions, 2 deletions
diff --git a/challenge-332/sgreen/README.md b/challenge-332/sgreen/README.md
index e9aff07864..55f79903ab 100644
--- a/challenge-332/sgreen/README.md
+++ b/challenge-332/sgreen/README.md
@@ -1,3 +1,3 @@
-# The Weekly Challenge 331
+# The Weekly Challenge 332
-Blog: [The last word is my buddy](https://dev.to/simongreennet/weekly-challenge-the-last-word-is-my-buddy-13pm)
+Blog: [I sent my date a letter](https://dev.to/simongreennet/weekly-challenge-i-sent-my-date-a-letter-1ppg)
diff --git a/challenge-332/sgreen/blog.txt b/challenge-332/sgreen/blog.txt
new file mode 100644
index 0000000000..79a8bbe873
--- /dev/null
+++ b/challenge-332/sgreen/blog.txt
@@ -0,0 +1 @@
+https://dev.to/simongreennet/weekly-challenge-i-sent-my-date-a-letter-1ppg \ No newline at end of file
diff --git a/challenge-332/sgreen/perl/ch-1.pl b/challenge-332/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..6a342a2f81
--- /dev/null
+++ b/challenge-332/sgreen/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+sub main ($input_string) {
+ # Split the input string by hyphens
+ my @date_parts = split /-/, $input_string;
+
+ # Convert each part to binary and remove the '0b' prefix
+ my @binary_parts = map { sprintf( "%b", $_ ) } @date_parts;
+
+ # Join the binary parts with hyphens
+ say join( '-', @binary_parts );
+}
+
+main( $ARGV[0] );
diff --git a/challenge-332/sgreen/perl/ch-2.pl b/challenge-332/sgreen/perl/ch-2.pl
new file mode 100755
index 0000000000..7869696ba7
--- /dev/null
+++ b/challenge-332/sgreen/perl/ch-2.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+use List::Util 'all';
+
+sub main ($input_string) {
+ my %freq = ();
+ for my $char ( split //, $input_string ) {
+ $freq{$char}++;
+ }
+
+ my $all_odd = all { $_ % 2 == 1 } values %freq;
+ say $all_odd ? "true" : "false";
+}
+
+main( $ARGV[0] );
diff --git a/challenge-332/sgreen/python/ch-1.py b/challenge-332/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..ece17b48dd
--- /dev/null
+++ b/challenge-332/sgreen/python/ch-1.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def binary_date(input_string: str) -> str:
+ """Convert a date string in the format 'YYYY-MM-DD' to a binary representation.
+
+ Args:
+ input_string (str): The date string in 'YYYY-MM-DD' format.
+
+ Returns:
+ str: The binary representation of the date, with parts separated by hyphens.
+ """
+
+ # Split the input string by hyphens
+ date_parts = input_string.split('-')
+
+ # Convert each part to binary and remove the '0b' prefix
+ binary_parts = [bin(int(part))[2:] for part in date_parts]
+
+ # Join the binary parts with hyphens
+ return '-'.join(binary_parts)
+
+
+def main():
+ result = binary_date(sys.argv[1])
+ print(result)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/challenge-332/sgreen/python/ch-2.py b/challenge-332/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..8a59970f37
--- /dev/null
+++ b/challenge-332/sgreen/python/ch-2.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+import sys
+from collections import Counter
+
+
+def odd_letters(input_string: str) -> bool:
+ """
+ Check if all letters in the input string have an odd frequency.
+
+ Args:
+ input_string (str): The input string to check.
+ Returns:
+ bool: True if all letters have an odd frequency, False otherwise.
+ """
+
+ freq = Counter(input_string)
+ return all(count % 2 == 1 for count in freq.values())
+
+
+def main():
+ result = odd_letters(sys.argv[1])
+ print(result)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/challenge-332/sgreen/python/test.py b/challenge-332/sgreen/python/test.py
new file mode 100755
index 0000000000..3e0d5e5c53
--- /dev/null
+++ b/challenge-332/sgreen/python/test.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+
+import unittest
+ch_1 = __import__('ch-1')
+ch_2 = __import__('ch-2')
+
+
+class TestClass(unittest.TestCase):
+ def test_ch_1(self):
+ self.assertEqual(
+ ch_1.binary_date('2025-07-26'),
+ '11111101001-111-11010'
+ )
+ self.assertEqual(
+ ch_1.binary_date('2000-02-02'),
+ '11111010000-10-10'
+ )
+ self.assertEqual(
+ ch_1.binary_date('2024-12-31'),
+ '11111101000-1100-11111'
+ )
+
+ def test_ch_2(self):
+ self.assertFalse(ch_2.odd_letters('weekly'))
+ self.assertTrue(ch_2.odd_letters('perl'))
+ self.assertFalse(ch_2.odd_letters('challenge'))
+
+
+if __name__ == '__main__':
+ unittest.main()