diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-10-23 01:04:50 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-10-23 01:06:43 +0100 |
| commit | ee2924132a7b0a54a6792bf050b8667b6c8852cf (patch) | |
| tree | 9ed346a64720ced7a9dda24c8c783680f1a294ca /challenge-135 | |
| parent | 8200f0ae411e06c5300bf3e3c60a0ed7f2201e50 (diff) | |
| download | perlweeklychallenge-club-ee2924132a7b0a54a6792bf050b8667b6c8852cf.tar.gz perlweeklychallenge-club-ee2924132a7b0a54a6792bf050b8667b6c8852cf.tar.bz2 perlweeklychallenge-club-ee2924132a7b0a54a6792bf050b8667b6c8852cf.zip | |
- Added Raku solution to "Middle 3-digits" task of week 135.
Diffstat (limited to 'challenge-135')
| -rw-r--r-- | challenge-135/mohammad-anwar/raku/ch-1.raku | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-135/mohammad-anwar/raku/ch-1.raku b/challenge-135/mohammad-anwar/raku/ch-1.raku new file mode 100644 index 0000000000..cd2a807584 --- /dev/null +++ b/challenge-135/mohammad-anwar/raku/ch-1.raku @@ -0,0 +1,35 @@ +#!/usr/bin/env raku + +=begin pod + +Week 135: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-135 + +Task #1: Middle 3-digits + + You are given an integer. + + Write a script find out the middle 3-digits of the given integer, if possible otherwise throw sensible error. + +Inspiration: + + Translated from the Perl solution as below: + + https://github.com/manwar/perlweeklychallenge-club/blob/master/challenge-135/mohammad-anwar/perl/ch-1.pl + +=end pod + +use v6.d; + +sub MAIN(Int $n) { + + my $num = $n.abs; + my $len = $num.chars; + + die "ERROR: Too short [$n]." if $len == 1; + die "ERROR: Even number of digits [$n]." if $len %% 2; + + my $i = ($len / 2) - 1; + $num.substr($i, 3).say; +} |
