From 1841df52444effa0ae8f14942eb25e5daf36357c Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Mon, 22 Nov 2021 10:27:22 +0100 Subject: ash 140, task 1 in Raku --- challenge-140/ash/raku/ch-1.raku | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 challenge-140/ash/raku/ch-1.raku 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; +} -- cgit