aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Shitov <andy@shitov.ru>2021-11-22 10:27:22 +0100
committerAndrew Shitov <andy@shitov.ru>2021-11-22 10:27:22 +0100
commit1841df52444effa0ae8f14942eb25e5daf36357c (patch)
treed019cf8d7b7f281e0e7bbceacbe84a958f678958
parent9d594ecfc11abdb82fc6de4408faebc54e54a506 (diff)
downloadperlweeklychallenge-club-1841df52444effa0ae8f14942eb25e5daf36357c.tar.gz
perlweeklychallenge-club-1841df52444effa0ae8f14942eb25e5daf36357c.tar.bz2
perlweeklychallenge-club-1841df52444effa0ae8f14942eb25e5daf36357c.zip
ash 140, task 1 in Raku
-rw-r--r--challenge-140/ash/raku/ch-1.raku21
1 files changed, 21 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;
+}