diff options
| author | Andinus <andinus@nand.sh> | 2021-10-22 20:14:53 +0530 |
|---|---|---|
| committer | Andinus <andinus@nand.sh> | 2021-10-22 20:14:53 +0530 |
| commit | f9e7ebe3ce76adf06c0e468954e72c2b29154803 (patch) | |
| tree | 19288baa061177f48e2388044424bb03ceb9f20c /challenge-135/andinus/README | |
| parent | c359de67ae716acbbd057182a4ce96c3a27f9aaa (diff) | |
| download | perlweeklychallenge-club-f9e7ebe3ce76adf06c0e468954e72c2b29154803.tar.gz perlweeklychallenge-club-f9e7ebe3ce76adf06c0e468954e72c2b29154803.tar.bz2 perlweeklychallenge-club-f9e7ebe3ce76adf06c0e468954e72c2b29154803.zip | |
Add challenge-135
Diffstat (limited to 'challenge-135/andinus/README')
| -rw-r--r-- | challenge-135/andinus/README | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/challenge-135/andinus/README b/challenge-135/andinus/README index 1d5171cfa8..bd1dd6e3ce 100644 --- a/challenge-135/andinus/README +++ b/challenge-135/andinus/README @@ -1,40 +1,51 @@ ━━━━━━━━━━━━━━━ - CHALLENGE 134 + CHALLENGE 135 Andinus ━━━━━━━━━━━━━━━ - 2021-10-11 + 2021-10-22 -Task 1 - Pandigital Numbers -═══════════════════════════ +Task 1 - Middle 3-digits +════════════════════════ - Write a script to generate first 5 Pandigital Numbers in base 10. + You are given an integer. - As per the [wikipedia], it says: - - A pandigital number is an integer that in a given base has - among its significant digits each digit used in the base - at least once. + 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 + └──── -[wikipedia] <https://en.wikipedia.org/wiki/Pandigital_number> Raku ──── - • Program: <file:raku/ch-1.raku> - - Loop from 1023456789 (first Pandigital Number) and take if it contains - every digit in base 10. + 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. ┌──── - │ put gather for 1023456789 .. ∞ { - │ .take if .comb>>.Int.Set ≡ (0 .. 9).Set; - │ }[^5] + │ $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); └──── |
