Self numbers: Difference between revisions

Content added Content deleted
m (→‎first 50 self numbers: added/changed whitespace and comments.)
m (→‎first 50 self numbers: added a feature to the program.)
Line 997: Line 997:
parse arg n . /*obtain optional argument from the CL.*/
parse arg n . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n= 50 /*Not specified? Then use the default.*/
if n=='' | n=="," then n= 50 /*Not specified? Then use the default.*/
tell = n>0; n= abs(n)
@.= . /*initialize the array of self numbers.*/
@.= . /*initialize the array of self numbers.*/
do j=1 for n*10 /*scan through ten times the #s wanted.*/
do j=1 for n*10 /*scan through ten times the #s wanted.*/
$= j /*1st part of sum is the number itself.*/
$= j /*1st part of sum is the number itself.*/
do k=1 for length(j) /*sum the decimal digits in the number.*/
do k=1 for length(j) /*sum the decimal digits in the number.*/
$= $ + substr(j, k, 1) /*add a particular digit to the sum. */
$= $ + substr(j, k, 1) /*add a particular digit to the sum. */
end /*k*/
end /*k*/
@.$= /*mark J as not being a self number. */
@.$= /*mark J as not being a self number. */
end /*j*/
end /*j*/
list= 1 /*initialize the list to the 1st number*/
list= 1 /*initialize the list to the 1st number*/
#= 1 /*the count of self numbers (so far). */
#= 1 /*the count of self numbers (so far). */
Line 1,011: Line 1,012:
end /*i*/
end /*i*/


say 'the first ' n " self numbers are:" /*display the title for the output list*/
say n " self numbers were found." /*display the title for the output list*/
say list /*display list of self numbers ──►term.*/
if tell then say list /*display list of self numbers ──►term.*/
exit 0 /*stick a fork in it, we're all done. */</lang>
exit 0 /*stick a fork in it, we're all done. */</lang>
{{out|output|text=&nbsp; when using the default input:}}
{{out|output|text=&nbsp; when using the default input:}}
<pre>
<pre>
the first 50 self numbers are:
50 self numbers were found.
1 3 5 7 9 20 31 42 53 64 75 86 97 108 110 121 132 143 154 165 176 187 198 209 211 222 233 244 255 266 277 288 299 310 312 323 334 345 356 367 378 389 400 411 413 424 435 446 457 468
1 3 5 7 9 20 31 42 53 64 75 86 97 108 110 121 132 143 154 165 176 187 198 209 211 222 233 244 255 266 277 288 299 310 312 323 334 345 356 367 378 389 400 411 413 424 435 446 457 468
</pre>
</pre>