Gapful numbers

From Fōrmulæ wiki
Jump to: navigation, search

This page is a solution to the task Gapful numbers in the Rosetta Code, written in Fōrmulæ.

Description (from Rosetta Code)

Numbers (expressed in base ten) that are (evenly) divisible by the number formed by the decimal digits of their first and last digit are known as gapful numbers.

All one─ and two─digit numbers have this property and are trivially excluded. Only numbers 100 will be considered for this Rosetta Code task.

Example

187 is a gapful number because it is evenly divisible by the number   17   which is formed by the first and last decimal digits of 187.

Task

  • Generate and show all sets of numbers (below) on one line (horizontally) with a title
  • Show the first 30 gapful numbers
  • Show the first 15 gapful numbers 1,000,000
  • Show the first 10 gapful numbers 1,000,000,000

Also see:

Solution

The following function return whether a given number is gapful:

  • The expression Digits creates a list of the digits of the given number, in any base (by default 10). For example, for the input 123, it reduces to {1, 2, 3}
  • The first subexpression (in the case of a list, an element of it) has the index 1. The last subexpression can be retrieved with the index -1 (-2 is the penultimate element and so on).
  • The expression Divides (shown here as a | b) reduces to True if a divides b, False elsewere.

GapfulNumbersCode01.png

The following function shows gapful numbers from a given value:

GapfulNumbersCode02.png

Case 1

Showing the first 30 gapful numbers:

GapfulNumbersCase01.png

Case 2

Showing the first 15 gapful numbers ≥ 1,000,000

GapfulNumbersCase02.png

Case 3

Showing the first 10 gapful numbers ≥ 1,000,000,000

GapfulNumbersCase03.png