aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-140/ash/raku/ch-1.raku21
-rw-r--r--challenge-140/ash/raku/ch-2.raku5
2 files changed, 26 insertions, 0 deletions
diff --git a/challenge-140/ash/raku/ch-1.raku b/challenge-140/ash/raku/ch-1.raku
new file mode 100644
index 0000000000..e7828a4c3e
--- /dev/null
+++ b/challenge-140/ash/raku/ch-1.raku
@@ -0,0 +1,21 @@
+class Binary {
+ has Str $.value;
+
+ method gist() returns Str {
+ return $.value;
+ }
+}
+
+# Do not forget "multi" here as otherwise it will overload too much, including the built-in infix:<+>(Int, Int).
+multi sub infix:<+>(Binary $a, Binary $b) returns Binary {
+ my Int $sum = "0b{$a.value}".Int + "0b{$b.value}".Int;
+
+ return Binary.new(value => $sum.base(2));
+}
+
+sub MAIN(IntStr $a, IntStr $b) {
+ my $x = Binary.new(value => $a);
+ my $y = Binary.new(value => $b);
+
+ say $x + $y;
+}
diff --git a/challenge-140/ash/raku/ch-2.raku b/challenge-140/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..948c313bb0
--- /dev/null
+++ b/challenge-140/ash/raku/ch-2.raku
@@ -0,0 +1,5 @@
+# This definitely is not efficient, but it displays the power of Raku syntax.
+
+sub MAIN($a, $b, $n) {
+ say (sort 1..$a X* 1..$b)[$n - 1]
+}