aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrir <rirans@comcast.net>2024-06-08 20:38:10 -0400
committerrir <rirans@comcast.net>2024-06-08 23:14:36 -0400
commit88f795dac39bfec75c3e8a2f2a9876c9720ca48f (patch)
tree1cbf65ce432bd5edd5783184ec4f9ba658becf56
parent5eb6d19fc4e8896f088ac554115e4f859647fb51 (diff)
downloadperlweeklychallenge-club-88f795dac39bfec75c3e8a2f2a9876c9720ca48f.tar.gz
perlweeklychallenge-club-88f795dac39bfec75c3e8a2f2a9876c9720ca48f.tar.bz2
perlweeklychallenge-club-88f795dac39bfec75c3e8a2f2a9876c9720ca48f.zip
272
-rw-r--r--challenge-272/0rir/raku/ch-1.raku42
-rw-r--r--challenge-272/0rir/raku/ch-2.raku78
2 files changed, 120 insertions, 0 deletions
diff --git a/challenge-272/0rir/raku/ch-1.raku b/challenge-272/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..4b98da9f99
--- /dev/null
+++ b/challenge-272/0rir/raku/ch-1.raku
@@ -0,0 +1,42 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+INIT $*RAT-OVERFLOW = FatRat;
+use lib $?FILE.IO.cleanup.parent(2).add("lib");
+use Test;
+
+=begin comment
+272-1: Defang IP Address Submitted by: Mohammad Sajid Anwar
+
+You are given a valid IPv4 address.
+
+Write a script to return the defanged version of the given IP address.
+
+A defanged IP address replaces every period “.” with “[.]".
+
+Example 1
+Input: $ip = "1.1.1.1"
+Output: "1[.]1[.]1[.]1"
+Example 2
+Input: $ip = "255.101.1.0"
+Output: "255[.]101[.]1[.]0"
+=end comment
+
+my @Test =
+
+ "1.1.1.1", "1[.]1[.]1[.]1",
+ "255.101.1.0", "255[.]101[.]1[.]0",
+;
+plan @Test ÷ 2;
+
+sub task( $a is copy) {
+ $a.subst: '.', '[.]', :g;
+}
+
+for @Test -> $in, $exp {
+ is task($in), $exp, "$exp <- $in";
+}
+
+done-testing;
+
+
diff --git a/challenge-272/0rir/raku/ch-2.raku b/challenge-272/0rir/raku/ch-2.raku
new file mode 100644
index 0000000000..a4543bee1b
--- /dev/null
+++ b/challenge-272/0rir/raku/ch-2.raku
@@ -0,0 +1,78 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+INIT $*RAT-OVERFLOW = FatRat;
+use lib $?FILE.IO.cleanup.parent(2).add("lib");
+use Test;
+
+=begin comment
+Task 2: String Score
+Submitted by: Mohammad Sajid Anwar
+You are given a string, $str.
+
+Write a script to return the score of the given string.
+
+The score of a string is defined as the sum of the absolute difference between the ASCII values of adjacent characters.
+
+Example 1
+Input: $str = "hello"
+Output: 13
+
+ASCII values of characters:
+h = 104
+e = 101
+l = 108
+l = 108
+o = 111
+
+Score => |104 - 101| + |101 - 108| + |108 - 108| + |108 - 111|
+ => 3 + 7 + 0 + 3
+ => 13
+Example 2
+Input: "perl"
+Output: 30
+
+ASCII values of characters:
+p = 112
+e = 101
+r = 114
+l = 108
+
+Score => |112 - 101| + |101 - 114| + |114 - 108|
+ => 11 + 13 + 6
+ => 30
+Example 3
+Input: "raku"
+Output: 37
+
+ASCII values of characters:
+r = 114
+a = 97
+k = 107
+u = 117
+
+Score => |114 - 97| + |97 - 107| + |107 - 117|
+ => 17 + 10 + 10
+ => 37
+=end comment
+
+my @Test =
+ "perl", 30,
+ "hello", 13,
+ "raku", 37,
+;
+plan @Test ÷ 2;
+
+
+sub task( $a) {
+ $a.comb».ord.rotor(2 => -1).map( { abs( .[0] - .[1])}).sum;
+
+}
+
+for @Test -> $in, $exp {
+ is task($in), $exp, "$exp <- $in";
+}
+
+done-testing;
+
+