aboutsummaryrefslogtreecommitdiff
path: root/challenge-307
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-02-10 02:40:40 +0000
committerGitHub <noreply@github.com>2025-02-10 02:40:40 +0000
commit83ec66faec7ab4a27bb38e1c7ad17d5a3d8fb930 (patch)
tree5b7d8fa04b96268238b7b6ce520a76649b4d8be2 /challenge-307
parent20203255d0f29f170a3c0cd55a737c0b2981597f (diff)
parent6f080fc3c36c5dd16f6ffb1b6e643fac6babc84b (diff)
downloadperlweeklychallenge-club-83ec66faec7ab4a27bb38e1c7ad17d5a3d8fb930.tar.gz
perlweeklychallenge-club-83ec66faec7ab4a27bb38e1c7ad17d5a3d8fb930.tar.bz2
perlweeklychallenge-club-83ec66faec7ab4a27bb38e1c7ad17d5a3d8fb930.zip
Merge pull request #11550 from 0rir/work
307
Diffstat (limited to 'challenge-307')
-rw-r--r--challenge-307/0rir/raku/ch-1.raku60
-rw-r--r--challenge-307/0rir/raku/ch-2.raku60
2 files changed, 120 insertions, 0 deletions
diff --git a/challenge-307/0rir/raku/ch-1.raku b/challenge-307/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..28c320c3b2
--- /dev/null
+++ b/challenge-307/0rir/raku/ch-1.raku
@@ -0,0 +1,60 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+use Test;
+
+=begin comment
+Task 1: Check Order
+Submitted by: Mohammad Sajid Anwar
+You are given an array of integers, @ints.
+
+Write a script to re-arrange the given array in an increasing order and return the indices where it differs from the original array.
+
+Example 1
+Input: @ints = (5, 2, 4, 3, 1)
+Output: (0, 2, 3, 4)
+
+Before: (5, 2, 4, 3, 1)
+After : (1, 2, 3, 4, 5)
+
+Difference at indices: (0, 2, 3, 4)
+Example 2
+Input: @ints = (1, 2, 1, 1, 3)
+Output: (1, 3)
+
+Before: (1, 2, 1, 1, 3)
+After : (1, 1, 1, 2, 3)
+
+Difference at indices: (1, 3)
+Example 3
+Input: @ints = (3, 1, 3, 2, 3)
+Output: (0, 1, 3)
+
+Before: (3, 1, 3, 2, 3)
+After : (1, 2, 3, 3, 3)
+
+Difference at indices: (0, 1, 3)
+
+=end comment
+
+my @Test =
+ (), (),
+ (1,), (),
+ (1,2), (),
+ (2,1), (0,1),
+ (1, 2, 1, 1, 3), (1, 3),
+ (5, 2, 4, 3, 1), (0, 2, 3, 4),
+ (3, 1, 3, 2, 3), (0, 1, 3),
+ (1, 204, 9, 7, 172, 238, 727, 319, 102), (1, 3, 5, 6, 8),
+;
+plan @Test ÷ 2;
+
+sub task( @in) { (@in.sort Z== @in) .grep: !*, :k }
+
+for @Test -> @in, $exp {
+ is task( @in), $exp, "{$exp // $exp.^name()} <- @in.raku()"
+}
+done-testing;
+
+my @int = 1, 204, 9, 7, 172, 238, 727, 102, 319;
+print "\nInput: @int = ( ", @int, " )\nOutput: ", task(@int);
diff --git a/challenge-307/0rir/raku/ch-2.raku b/challenge-307/0rir/raku/ch-2.raku
new file mode 100644
index 0000000000..99912d1c2b
--- /dev/null
+++ b/challenge-307/0rir/raku/ch-2.raku
@@ -0,0 +1,60 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+use Test;
+
+=begin comment
+307-Task 2: Find Anagrams Submitted by: Mohammad Sajid Anwar
+You are given a list of words, @words.
+
+Write a script to find any two consecutive words and if they are anagrams, drop the first word and keep the second. You continue this until there is no more anagrams in the given list and return the count of final list.
+
+Example 1
+Input: @words = ("acca", "dog", "god", "perl", "repl")
+Output: 3
+
+Step 1: "dog" and "god" are anagrams, so dropping "dog" and keeping "god" => ("acca", "god", "perl", "repl")
+Step 2: "perl" and "repl" are anagrams, so dropping "perl" and keeping "repl" => ("acca", "god", "repl")
+Example 2
+Input: @words = ("abba", "baba", "aabb", "ab", "ab")
+Output: 2
+
+Step 1: "abba" and "baba" are anagrams, so dropping "abba" and keeping "baba" => ("baba", "aabb", "ab", "ab")
+Step 2: "baba" and "aabb" are anagrams, so dropping "baba" and keeping "aabb" => ("aabb", "ab", "ab")
+Step 3: "ab" and "ab" are anagrams, so dropping "ab" and keeping "ab" => ("aabb", "ab")
+
+=end comment
+
+my @Test =
+ (), 0,
+ ('ab',), 1,
+ ('ba', 'ab'), 1,
+ ('ac', 'ba'), 2,
+ ("abba", "baba", "aabb", "ab", "ab"), 2,
+ ("acca", "dog", "god", "perl", "repl"), 3,
+ ('fussy', 'fuzzy', 'fussy', 'furry',), 4,
+ ('fuzzy', 'fussy', 'fussy', 'furry',), 3,
+ ('ab', 'ba', 'ab', 'ba', 'da'), 2,
+ ('ab', 'da', 'ba', 'ab', 'ba'), 3,
+ ('ab', 'ba', 'ab', 'da', 'ba'), 3,
+;
+plan @Test ÷ 2;
+
+only task( @a is copy -->Int) {
+ my $deleted = 0;
+ @a.=map({.split('').sort.join });
+ for 1..^@a -> $i {
+ ++$deleted if @a[$i-1] eq @a[$i];
+ }
+ @a.elems - $deleted;
+}
+
+for @Test -> @a, $exp {
+ is task( @a), $exp, "{$exp // $exp.^name()} <- @a.raku()"
+}
+done-testing;
+
+my @word = "acca", "dog", "god", "perl", "repl";
+say "\nInput: @word = ( ", @word.map('"' ~ * ~ '"' ).join(' ,'), ")";
+say "Output: ", @word.&task;
+