31 lines
995 B
Text
31 lines
995 B
Text
ClearAll[GapfulQ, GetFirstPalindromicGapfulNumbers]
|
|
GapfulQ[n_Integer] := Divisible[n, FromDigits[IntegerDigits[n][[{1, -1}]]]]
|
|
GetFirstPalindromicGapfulNumbers[startend_, n_Integer] :=
|
|
Module[{out = {}, i, new, digs, id},
|
|
digs = 1;
|
|
While[Length[out] < n,
|
|
Do[
|
|
id = IntegerDigits[i, 10, Ceiling[digs/2]];
|
|
If[OddQ[digs],
|
|
new = Join[{startend}, id, Rest@Reverse[id], {startend}]
|
|
,
|
|
new = Join[{startend}, id, Reverse[id], {startend}]
|
|
];
|
|
new //= FromDigits;
|
|
If[GapfulQ[new],
|
|
AppendTo[out, new]
|
|
];
|
|
i++;
|
|
,
|
|
{i, 0, 10^Ceiling[digs/2] - 1}
|
|
];
|
|
digs += 1;
|
|
];
|
|
Take[out, n]
|
|
]
|
|
Print["First 20 palindromic gapful numbers >100 ending with each digit from 1 to 9:"]
|
|
Print[GetFirstPalindromicGapfulNumbers[#, 20]] & /@ Range[9];
|
|
Print["86th to 100th:"]
|
|
Print[GetFirstPalindromicGapfulNumbers[#, 100][[86 ;; 100]]] & /@ Range[9];
|
|
Print["991st to 1000th:"]
|
|
Print[GetFirstPalindromicGapfulNumbers[#, 1000][[991 ;; 1000]]] & /@ Range[9];
|