Upside-down numbers
An upside-down number is a positive base 10 integer whose i-th leftmost and i-th rightmost digits are complements, i.e., their sum is 10.
Upside-down numbers is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
- For example
7165493 is an upside-down number. 7 + 3 = 10 1 + 9 = 10 6 + 4 = 10 5 + 5 = 10
From that definition it follows that an upside-down number cannot contain any zeros, and if there is an odd number of digits, then the center digit must be a 5.
- Task
- Write a routine to find (or generate) upside-down numbers.
- Find and show the first 50 upside-down numbers.
- Find and show the five hundredth upside-down number.
- Find and show the five thousandth upside-down number.
- Stretch
- Find and show the fifty thousandth, five hundred thousandth, five millionth upside-down number.
- See also
Raku
use Lingua::EN::Numbers;
sub udgen (@r) {
my @u = @r.hyper.map: { next if .contains: 0; ($_, (10 «-« .flip.comb).join) };
@u».join, @u».join(5)
}
my @upside-downs = lazy flat 5, (^∞).map({ udgen exp($_,10) .. exp(1+$_,10) });
say "First fifty upside-downs:\n" ~ @upside-downs[^50].batch(10)».fmt("%4d").join: "\n";
say '';
for 5e2, 5e3, 5e4, 5e5, 5e6 {
say "{.Int.&ordinal.tc}: " ~ comma @upside-downs[$_-1]
}
- Output:
First fifty upside-downs: 5 19 28 37 46 55 64 73 82 91 159 258 357 456 555 654 753 852 951 1199 1289 1379 1469 1559 1649 1739 1829 1919 2198 2288 2378 2468 2558 2648 2738 2828 2918 3197 3287 3377 3467 3557 3647 3737 3827 3917 4196 4286 4376 4466 Five hundredth: 494,616 Five thousandth: 56,546,545 Fifty thousandth: 6,441,469,664 Five hundred thousandth: 729,664,644,183 Five millionth: 82,485,246,852,682