From 932b42303fb5cd04b80c13e4da44676684c48b8c Mon Sep 17 00:00:00 2001 From: rir Date: Sun, 3 Aug 2025 14:04:54 -0400 Subject: 332 --- challenge-332/0rir/raku/ch-1.raku | 46 +++++++++++++++++++++++++++++++ challenge-332/0rir/raku/ch-2.raku | 57 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 challenge-332/0rir/raku/ch-1.raku create mode 100644 challenge-332/0rir/raku/ch-2.raku diff --git a/challenge-332/0rir/raku/ch-1.raku b/challenge-332/0rir/raku/ch-1.raku new file mode 100644 index 0000000000..635b478317 --- /dev/null +++ b/challenge-332/0rir/raku/ch-1.raku @@ -0,0 +1,46 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴ 🐧 +use v6.d; +use Test; + +=begin comment +332-Task 1: Binary Date Submitted by: Mohammad Sajid Anwar +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" +=end comment + +my @Test = + "2025-07-26", "11111101001-111-11010", + "2000-02-02", "11111010000-10-10", + "2024-12-31", "11111101000-1100-11111", +; +plan +@Test ÷ 2; + +sub task( $a) { + join '-', $a.split( '-').map: *.Int.base(2); +} + +for @Test -> $in, $exp { + is task( $in), $exp, "{$exp // $exp.^name()} <- $in.raku()"; +} +done-testing; + +my $date = "2525-01-01"; +say " +Input: \$date = \"$date\" +Output: \"", &task( $date), '"'; + diff --git a/challenge-332/0rir/raku/ch-2.raku b/challenge-332/0rir/raku/ch-2.raku new file mode 100644 index 0000000000..d2d7a2f02f --- /dev/null +++ b/challenge-332/0rir/raku/ch-2.raku @@ -0,0 +1,57 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴ 🐧 +use v6.d; +use Test; + +=begin comment +332-Task 2: Odd Letters Submitted by: Mohammad Sajid Anwar +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 +=end comment + +my @Test = + "weekly", False, + "perl", True, + "challenge", False, + "abcdefghijk", True, + 'a-b_c+d×e%f&123()gh=ijk', True, + 'a-a_c+d×e%f&123()gh=ijk', False, +; +plan +@Test ÷ 2; + +sub task( Str $a -->Bool) { + !defined + $a.comb.grep( /<:L>/ ) + .Bag.first( :k, *.value %% 2[0]) +} + +for @Test -> $in, $exp { + is task( $in), $exp, "{$exp // $exp.^name()} <- $in.raku()"; +} +done-testing; + +my $source = "mn * o - p + qr - s^^3 ~ aaa # wxyz"; +say qq{\nInput: \$source = "$source"\n} + ~ qq{Output: &task($source)}; -- cgit