aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-061/noud/raku/ch-1.p619
-rw-r--r--challenge-061/noud/raku/ch-2.p631
2 files changed, 50 insertions, 0 deletions
diff --git a/challenge-061/noud/raku/ch-1.p6 b/challenge-061/noud/raku/ch-1.p6
new file mode 100644
index 0000000000..56d2fb9543
--- /dev/null
+++ b/challenge-061/noud/raku/ch-1.p6
@@ -0,0 +1,19 @@
+# Given a list of 4 or more numbers, write a script to find the contiguous
+# sublist that has the maximum product. The length of the sublist is
+# irrelevant; your job is to maximize the product.
+#
+# Example
+#
+# Input: [ 2, 5, -1, 3 ]
+#
+# Output: [ 2, 5 ] which gives maximum product 10.
+
+sub max-conseq-prod(@a) {
+ gather for ^@a.elems -> $i {
+ for $i+1..^@a.elems -> $j {
+ take @a[$i..$j];
+ }
+ }.sort({ .reduce(&[*]) })[*-1];
+}
+
+max-conseq-prod([2, 5, -1, 3]).say;
diff --git a/challenge-061/noud/raku/ch-2.p6 b/challenge-061/noud/raku/ch-2.p6
new file mode 100644
index 0000000000..b2d884d97a
--- /dev/null
+++ b/challenge-061/noud/raku/ch-2.p6
@@ -0,0 +1,31 @@
+# You are given a string containing only digits (0..9). The string should have
+# between 4 and 12 digits.
+#
+# Write a script to print every possible valid IPv4 address that can be made by
+# partitioning the input string.
+#
+# For the purpose of this challenge, a valid IPv4 address consists of four
+# “octets” i.e. A, B, C and D, separated by dots (.).
+#
+# Each octet must be between 0 and 255, and must not have any leading zeroes.
+# (e.g., 0 is OK, but 01 is not.)
+#
+# Example
+#
+# Input: 25525511135,
+#
+# Output:
+#
+# 255.255.11.135
+# 255.255.111.35
+
+sub parse-to-ipv4($s) {
+ gather for $s ~~ m:ex/ ^ ((\d ** 1..3) <?{ $0 < 256 }>) ** 4 $ / -> $r {
+ take $r[0].join('.');
+ }
+}
+
+parse-to-ipv4('25525511135').say;
+parse-to-ipv4('127001').say;
+parse-to-ipv4('0000').say;
+