Inconsummate numbers in base 10
Inconsummate numbers in base 10 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.
A consummate number is a non-negative integer that can be formed by some integer N divided by the the digital sum of N.
- For instance
47 is a consummate number.
846 / (8 + 4 + 6) = 47
On the other hand, there are integers that can not be formed by a ratio of any integer over its digital sum. These numbers are known as inconsummate numbers.
62 is an inconsummate number. There is no integer ratio of an integer to its digital sum that will result in 62.
The base that a number is expressed in will affect whether it is inconsummate or not. This task will be restricted to base 10.
- Task
- Write a routine to find inconsummate numbers in base 10;
- Use that routine to find and display the first fifty inconsummate numbers.
- Stretch
- Use that routine to find and display the one thousandth inconsummate number.
- See also
Raku
Not really pleased with this entry. It works, but seems inelegant.
my $upto = 1000;
my @ratios = unique (^∞).race.map({($_ / .comb.sum).narrow})[^($upto²)].grep: Int;
my @incons = (sort keys (1..$upto * 10) (-) @ratios)[^$upto];
put "First fifty inconsummate numbers (in base 10):\n" ~ @incons[^50]».fmt("%3d").batch(10).join: "\n";
put "\nOne thousandth: " ~ @incons[999]
- Output:
First fifty inconsummate numbers (in base 10): 62 63 65 75 84 95 161 173 195 216 261 266 272 276 326 371 372 377 381 383 386 387 395 411 416 422 426 431 432 438 441 443 461 466 471 476 482 483 486 488 491 492 493 494 497 498 516 521 522 527 One thousandth: 6996