Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Self-numbers/REXX/self-numbers-1.rexx
Normal file
20
Task/Self-numbers/REXX/self-numbers-1.rexx
Normal 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.*/
|
||||
37
Task/Self-numbers/REXX/self-numbers-2.rexx
Normal file
37
Task/Self-numbers/REXX/self-numbers-2.rexx
Normal 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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue