aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Köhler <jean-luc@picard.franken.de>2025-07-30 20:44:38 +0200
committerThomas Köhler <jean-luc@picard.franken.de>2025-07-30 20:44:38 +0200
commit3aa57db3e4b77485b657e15dbfa49642f3f36f5f (patch)
treea93e85389e3eb9f891c18ea2aba7f7d0a4e52fdc
parent1ff2c9796a511d63231d3757acb27e4046a91fb2 (diff)
downloadperlweeklychallenge-club-3aa57db3e4b77485b657e15dbfa49642f3f36f5f.tar.gz
perlweeklychallenge-club-3aa57db3e4b77485b657e15dbfa49642f3f36f5f.tar.bz2
perlweeklychallenge-club-3aa57db3e4b77485b657e15dbfa49642f3f36f5f.zip
Add solution 332.
Signed-off-by: Thomas Köhler <jean-luc@picard.franken.de>
-rw-r--r--challenge-332/jeanluc2020/blog-1.txt1
-rw-r--r--challenge-332/jeanluc2020/blog-2.txt1
-rwxr-xr-xchallenge-332/jeanluc2020/perl/ch-1.pl72
-rwxr-xr-xchallenge-332/jeanluc2020/perl/ch-2.pl66
4 files changed, 140 insertions, 0 deletions
diff --git a/challenge-332/jeanluc2020/blog-1.txt b/challenge-332/jeanluc2020/blog-1.txt
new file mode 100644
index 0000000000..1398936d21
--- /dev/null
+++ b/challenge-332/jeanluc2020/blog-1.txt
@@ -0,0 +1 @@
+http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-332-1.html
diff --git a/challenge-332/jeanluc2020/blog-2.txt b/challenge-332/jeanluc2020/blog-2.txt
new file mode 100644
index 0000000000..a348aec548
--- /dev/null
+++ b/challenge-332/jeanluc2020/blog-2.txt
@@ -0,0 +1 @@
+http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-332-2.html
diff --git a/challenge-332/jeanluc2020/perl/ch-1.pl b/challenge-332/jeanluc2020/perl/ch-1.pl
new file mode 100755
index 0000000000..85cd01a7f9
--- /dev/null
+++ b/challenge-332/jeanluc2020/perl/ch-1.pl
@@ -0,0 +1,72 @@
+#!/usr/bin/env perl
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-332/#TASK1
+#
+# Task 1: Binary Date
+# ===================
+#
+# You are given a date in the format YYYY-MM-DD.
+#
+# Write a script to convert it into binary date.
+#
+# Example 1
+#
+# Input: $date = "2025-07-26"
+# Output: "11111101001-111-11010"
+#
+#
+# Example 2
+#
+# Input: $date = "2000-02-02"
+# Output: "11111010000-10-10"
+#
+#
+# Example 3
+#
+# Input: $date = "2024-12-31"
+# Output: "11111101000-1100-11111"
+#
+############################################################
+##
+## discussion
+##
+############################################################
+#
+# We split the date into its single parts, then we create the
+# binary representation for all of those and put them together
+# again in the end.
+# To turn a number into its binary representation, we just check
+# wether it is even or not so we know whether the last digit will
+# be a "1" or a "0", and append that to the binary representation
+# of the integer value of the number divided by 2. Of course we
+# return an empty string in case of an input of "0" to stop
+# processing.
+
+use v5.36;
+
+binary_date("2025-07-26");
+binary_date("2000-02-02");
+binary_date("2024-12-31");
+
+
+sub binary_date($date) {
+ say "Input: \"$date\"";
+ my @numbers = split /-/, $date;
+ my @binary_numbers = ();
+ foreach my $num (@numbers) {
+ push @binary_numbers, binary($num);
+ }
+ my $binary_date = join("-", @binary_numbers);
+ say "Output: \"$binary_date\"";
+}
+
+sub binary($decimal) {
+ if($decimal > 0) {
+ if($decimal % 2) {
+ return binary(int($decimal/2)) . "1";
+ } else {
+ return binary(int($decimal/2)) . "0";
+ }
+ }
+ return "";
+}
+
diff --git a/challenge-332/jeanluc2020/perl/ch-2.pl b/challenge-332/jeanluc2020/perl/ch-2.pl
new file mode 100755
index 0000000000..60b8f10b40
--- /dev/null
+++ b/challenge-332/jeanluc2020/perl/ch-2.pl
@@ -0,0 +1,66 @@
+#!/usr/bin/env perl
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-332/#TASK2
+#
+# Task 2: Odd Letters
+# ===================
+#
+# You are given a string.
+#
+# Write a script to find out if each letter in the given string appeared odd number of times.
+#
+## Example 1
+##
+## Input: $str = "weekly"
+## Output: false
+##
+## w: 1 time
+## e: 2 times
+## k: 1 time
+## l: 1 time
+## y: 1 time
+##
+## The letter 'e' appeared 2 times i.e. even.
+#
+#
+## Example 2
+##
+## Input: $str = "perl"
+## Output: true
+#
+#
+## Example 3
+##
+## Input: $source = "challenge"
+## Output: false
+#
+############################################################
+##
+## discussion
+##
+############################################################
+#
+# We split the input into its individual characters and count
+# each occurence by using a hash table. In the end, we check
+# each letter whether it occurs an odd or even number of times.
+# If any number occurs an even amount of times, we return false
+# immediately. In the end, we can return true.
+
+use v5.36;
+
+odd_letters("weekly");
+odd_letters("perl");
+odd_letters("challenge");
+
+sub odd_letters($str) {
+ say "Input: \"$str\"";
+ my $map = {};
+ foreach my $l (split //, $str) {
+ $map->{$l}++;
+ }
+ foreach my $l (keys %$map) {
+ if( $map->{$l} % 2 == 0) {
+ return say "Output: false";
+ }
+ }
+ say "Output: true";
+}