diff options
| author | drbaggy <js5@sanger.ac.uk> | 2022-01-10 09:18:04 +0000 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2022-01-10 09:18:04 +0000 |
| commit | 54edabaf2afeb407d01d88c19d894823f85d5125 (patch) | |
| tree | 4e4a4fbda6b3023c3d3840a1daae50a49fca9c86 /challenge-147/andinus/README | |
| parent | 29b9eeeb95555dbcf1f375c89910c83ac83abd8d (diff) | |
| parent | e9411bdc7658179af3f23d3ada7970323547a7d7 (diff) | |
| download | perlweeklychallenge-club-54edabaf2afeb407d01d88c19d894823f85d5125.tar.gz perlweeklychallenge-club-54edabaf2afeb407d01d88c19d894823f85d5125.tar.bz2 perlweeklychallenge-club-54edabaf2afeb407d01d88c19d894823f85d5125.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-147/andinus/README')
| -rw-r--r-- | challenge-147/andinus/README | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/challenge-147/andinus/README b/challenge-147/andinus/README new file mode 100644 index 0000000000..bd1dd6e3ce --- /dev/null +++ b/challenge-147/andinus/README @@ -0,0 +1,51 @@ + ━━━━━━━━━━━━━━━ + CHALLENGE 135 + + Andinus + ━━━━━━━━━━━━━━━ + + + 2021-10-22 + + + + + +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. + + ┌──── + │ Input: $n = 1234567 + │ Output: 345 + │ + │ Input: $n = -123 + │ Output: 123 + │ + │ Input: $n = 1 + │ Output: too short + │ + │ Input: $n = 10 + │ Output: even number of digits + └──── + + +Raku +──── + + Input's absolute value is taken because the sign is meaningless here. + To get middle 3-digits we take 3 digits from `$n.chars div 2 - 1' + position, `-1' because Arrays are 0-indexed. It's guaranteed that we + have odd number of digits so `div 2' will land us on left of middle + digit, we just take 3 digits from there. + + ┌──── + │ $n = abs $n; + │ die "too short" if $n.chars < 3; + │ die "even number of digits" if $n.chars %% 2; + │ put $n.substr($n.chars div 2 - 1, 3); + └──── |
