Data update

This commit is contained in:
Ingy döt Net 2024-07-13 15:19:22 -07:00
parent 29a5eea0d4
commit 5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions

View file

@ -1,24 +1,18 @@
Numbers   (positive integers expressed in base ten)   that are (evenly) divisible by the number formed by the
first and last digit are known as   '''gapful numbers'''.
For this task, a ''number'' is to be understood as a positive integer expressed in base ten,
and a ''palindromic'' number is one that is equal to the integer formed by reversing its decimal digits.
A number that is evenly divisible by the number formed by concatenating its
first and last digits in that order is known as a '''gapful number'''.
All one─ and two─digit numbers have this property and accordingly only
numbers greater than or equal to '''100''' should be considered for this Rosetta Code task.
''Evenly divisible''   means divisible with   no   remainder.
All   one─   and two─digit   numbers have this property and are trivially excluded.   Only
numbers &nbsp; <big> &ge; </big> '''100''' &nbsp; will be considered for this Rosetta Code task.
(''Evenly divisible'' here means divisible with no remainder.)
;Example:
<big>'''1037'''</big> &nbsp; is a &nbsp; '''gapful''' &nbsp; number because it is evenly divisible by the
number &nbsp; <big>'''17'''</big> &nbsp; which is formed by the first and last decimal digits
of &nbsp; <big> '''<u>1</u>03<u>7</u>'''. </big>
A palindromic number is &nbsp; (for this task, a positive integer expressed in base ten), &nbsp; when the number is
reversed, &nbsp; is the same as the original number.
;Task:
:* &nbsp; Show &nbsp; (nine sets) &nbsp; the first &nbsp; '''20''' &nbsp; palindromic gapful numbers that &nbsp; ''end'' &nbsp; with:
:::* &nbsp; the digit &nbsp; '''1'''

View file

@ -0,0 +1,68 @@
### Generic functions
def power($a;$b): reduce range(0;$b) as $i (1; . * $a);
# Emit the reverse of the string $s
def reverse($s):
$s | tostring | split("") | reverse | join("");
def skip($n; stream):
foreach stream as $s (-1;
if . == $n then . else .+1 end;
select(. == $n) | $s);
### Palindromic gapful numbers
# Output: a stream of non-trivial palindromic gapful numbers ending in the specified digit
def palindromicgapfuls($digit):
{emit: null,
dd: (11 * $digit), # digit gapful divisor: 11, 22,...88, 99
power: 1}
| foreach range(0; infinite) as $_ (.;
.power += 1
| (power(10; .power / 2 | floor)) as $base # value of middle digit position: 10..
| ($base * 11) as $base11 # value of middle two digits positions: 110..
| ($base * $digit) as $this_lo # starting half for this digit: 10.. to 90..
| ($base * ($digit + 1)) as $next_lo # starting half for next digit: 20.. to 100..
| foreach range($this_lo; $next_lo; 10) as $front_half (.; # d_00; d_10; d_20; ...
($front_half|tostring) as $left_half
| reverse($left_half) as $right_half
| if .power%2 == 1
then .palindrome = (($left_half + $right_half) | tonumber)
| foreach range(0;10) as $i (.;
.emit = if .palindrome % .dd == 0
then .palindrome
else null
end
| .palindrome += $base11 )
else .palindrome = ((($left_half[:-1]) + $right_half) | tonumber)
| foreach range(0;10) as $i (.;
.emit = if .palindrome % .dd == 0
then .palindrome
else null
end
| .palindrome += $base )
end ) )
| select(.emit).emit ;
def palindromicgapfuls($count; $keep):
range(1; 10) as $digit
| "\($digit) : \([limit($keep; skip($count - $keep; palindromicgapfuls($digit)))])" ;
def task:
"First 20 non-trivial palindromic gapful numbers ending with:",
palindromicgapfuls(20; 20),
"\nLast 15 of first 100 non-trivial palindromic gapful numbers ending in:",
palindromicgapfuls(100; 15),
"\nLast 10 of first 1000 non-trivial palindromic gapful numbers ending in:",
palindromicgapfuls(1000; 10),
"\n100,000th non-trivial palindromic gapful number ending with:",
palindromicgapfuls(100000; 1),
"\n1,000,000th non-trivial palindromic gapful number ending with:",
palindromicgapfuls(1000000; 1);
task