diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-11-24 00:58:38 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-24 00:58:38 +0000 |
| commit | e89d742b7cd69a28e22768a5395df1b1b329dbe5 (patch) | |
| tree | fd7eb6962b29ce1073c08784bb4c25c35cb5541c | |
| parent | 5c2d1e2ff6d4c85c12278bb37cc2ccb6fe036764 (diff) | |
| parent | 1841df52444effa0ae8f14942eb25e5daf36357c (diff) | |
| download | perlweeklychallenge-club-e89d742b7cd69a28e22768a5395df1b1b329dbe5.tar.gz perlweeklychallenge-club-e89d742b7cd69a28e22768a5395df1b1b329dbe5.tar.bz2 perlweeklychallenge-club-e89d742b7cd69a28e22768a5395df1b1b329dbe5.zip | |
Merge pull request #5261 from ash/ash-140
ash 140, task 2 in Raku
| -rw-r--r-- | challenge-140/ash/raku/ch-1.raku | 21 | ||||
| -rw-r--r-- | challenge-140/ash/raku/ch-2.raku | 5 |
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] +} |
