aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwanderdoc <wanderdoc@users.noreply.github.com>2025-08-03 17:40:38 +0200
committerGitHub <noreply@github.com>2025-08-03 17:40:38 +0200
commit8da1d01fed0fd98f505b42adb712caa8f8b6055e (patch)
tree76a3b69c37011b5b6c3debcc7ef08e805a6854c9
parentd904375e9cf226c2c0465204e98b35fadf52be91 (diff)
downloadperlweeklychallenge-club-8da1d01fed0fd98f505b42adb712caa8f8b6055e.tar.gz
perlweeklychallenge-club-8da1d01fed0fd98f505b42adb712caa8f8b6055e.tar.bz2
perlweeklychallenge-club-8da1d01fed0fd98f505b42adb712caa8f8b6055e.zip
Create ch-1.pl
-rw-r--r--challenge-332/wanderdoc/perl/ch-1.pl43
1 files changed, 43 insertions, 0 deletions
diff --git a/challenge-332/wanderdoc/perl/ch-1.pl b/challenge-332/wanderdoc/perl/ch-1.pl
new file mode 100644
index 0000000000..2e95199cd8
--- /dev/null
+++ b/challenge-332/wanderdoc/perl/ch-1.pl
@@ -0,0 +1,43 @@
+#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+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"
+
+=cut
+
+use Test2::V0 -no_srand => 1;
+
+is(binary_date('2025-07-26'), '11111101001-111-11010', 'Example 1');
+is(binary_date('2000-02-02'), '11111010000-10-10', 'Example 2');
+is(binary_date('2024-12-31'), '11111101000-1100-11111', 'Example 3');
+done_testing();
+
+sub binary_date
+{
+ my $str = $_[0];
+ return join('-',
+ map { sprintf("%b", $_) }
+ split(/\-/, $str, -1));
+
+
+}