Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,20 @@
/*REXX program displays N self numbers (aka Colombian or Devlali numbers). OEIS A3052.*/
parse arg n . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n= 50 /*Not specified? Then use the default.*/
tell = n>0; n= abs(n) /*TELL: show the self numbers if N>0 */
@.= . /*initialize the array of self numbers.*/
do j=1 for n*10 /*scan through ten times the #s wanted.*/
$= j /*1st part of sum is the number itself.*/
do k=1 for length(j) /*sum the decimal digits in the number.*/
$= $ + substr(j, k, 1) /*add a particular digit to the sum. */
end /*k*/
@.$= /*mark J as not being a self number. */
end /*j*/ /* ─── */
list= 1 /*initialize the list to the 1st number*/
#= 1 /*the count of self numbers (so far). */
do i=3 until #==n; if @.i=='' then iterate /*Not a self number? Then skip it. */
#= # + 1; list= list i /*bump counter of self #'s; add to list*/
end /*i*/
/*stick a fork in it, we're all done. */
say n " self numbers were found." /*display the title for the output list*/
if tell then say list /*display list of self numbers ──►term.*/

View file

@ -0,0 +1,37 @@
/*REXX pgm displays the Nth self number, aka Colombian or Devlali numbers. OEIS A3052.*/
numeric digits 20 /*ensure enough decimal digits for #. */
parse arg high . /*obtain optional argument from the CL.*/
if high=='' | high=="," then high= 10000000 /*Not specified? Then use 10M default.*/
i= 1; pow= 10; digs= 1; offset= 9; $= 0 /*$: the last self number found. */
#= 0 /*count of self numbers (so far). */
do while #<high; isSelf= 1 /*assume a self number (so far). */
start= max(i-offset, 0) /*find start #; must be non-negative. */
sum= sumDigs(start) /*obtain the sum of the decimal digits.*/
do j=start to i-1
if j+sum==i then do; isSelf= 0 /*found a non self number. */
iterate /*keep looking for more self numbers. */
end
if (j+1)//10==0 then sum= sumDigs(j+1) /*obtain the sum of the decimal digits.*/
else sum= sum + 1 /*bump " " " " " " */
end /*j*/
if isSelf then do; #= # + 1 /*bump the count of self numbers. */
$= i /*save the last self number found. */
end
i= i + 1 /*bump the self number by unity. */
if i//pow==0 then do; digs= digs + 1 /* " " number of decimal digits. */
pow= pow * 10 /* " " power " a factor of ten. */
offset= digs * 9 /* " " offset " " " " nine. */
end
end /*while*/
say
say 'the ' commas(high)th(high) " self number is: " commas($)
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
sumDigs: parse arg s 2 x; do k=1 for length(x) /*get 1st dig, & also get the rest.*/
s= s + substr(x, k, 1) /*add a particular digit to the sum.*/
end /*k*/; return s
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg _; do c=length(_)-3 to 1 by -3; _=insert(',', _, c); end; return _
th: parse arg th; return word('th st nd rd', 1 +(th//10)*(th//100%10\==1)*(th//10<4))