diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-08-03 23:13:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-03 23:13:41 +0100 |
| commit | 8d9614e549a551242b4f01ab81db31572f284534 (patch) | |
| tree | 87055aed571c9a19499dde038d7b3a3a05e64b42 | |
| parent | 8694075ce2d0d1115b8a67b6a2b20a996020519b (diff) | |
| parent | 30726639df5ec46e15183b7dc65d51704f1a7395 (diff) | |
| download | perlweeklychallenge-club-8d9614e549a551242b4f01ab81db31572f284534.tar.gz perlweeklychallenge-club-8d9614e549a551242b4f01ab81db31572f284534.tar.bz2 perlweeklychallenge-club-8d9614e549a551242b4f01ab81db31572f284534.zip | |
Merge pull request #12452 from wanderdoc/master
PWC 332 (wanderdoc)
| -rw-r--r-- | challenge-332/wanderdoc/perl/ch-1.pl | 43 | ||||
| -rw-r--r-- | challenge-332/wanderdoc/perl/ch-2.pl | 59 |
2 files changed, 102 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)); + + +} diff --git a/challenge-332/wanderdoc/perl/ch-2.pl b/challenge-332/wanderdoc/perl/ch-2.pl new file mode 100644 index 0000000000..8ec58accc2 --- /dev/null +++ b/challenge-332/wanderdoc/perl/ch-2.pl @@ -0,0 +1,59 @@ +#!perl +use strict; +use warnings FATAL => qw(all); + +=prompt +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 + +=cut + +use constant { true => 1, false => 0 }; +use Test2::V0 -no_srand => 1; + + + +is(odd_letters('weekly'), false, 'Example 1'); +is(odd_letters('perl'), true, 'Example 2'); +is(odd_letters('challenge'), false, 'Example 3'); +done_testing(); + +sub odd_letters +{ + my $str = $_[0]; + my %letters; + $letters{$_}++ for split(//, $str); + for my $num ( values %letters ) + { + if ( $num % 2 == 0 ) + { + return false; + } + } + return true; +} |
