Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Happy-numbers/NetRexx/happy-numbers.netrexx
Normal file
28
Task/Happy-numbers/NetRexx/happy-numbers.netrexx
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/*NetRexx program to display the 1st 8 (or specified arg) happy numbers*/
|
||||
limit = arg[0] /*get argument for LIMIT. */
|
||||
say limit
|
||||
if limit = null, limit ='' then limit=8 /*if not specified, set LIMIT to 8*/
|
||||
haps = 0 /*count of happy numbers so far. */
|
||||
|
||||
loop n=1 while haps < limit /*search integers starting at one.*/
|
||||
q=n /*Q may or may not be "happy". */
|
||||
a=0
|
||||
|
||||
loop forever /*see if Q is a happy number. */
|
||||
if q==1 then do /*if Q is unity, then it's happy*/
|
||||
haps = haps + 1 /*bump the count of happy numbers.*/
|
||||
say n /*display the number. */
|
||||
iterate n /*and then keep looking for more. */
|
||||
end
|
||||
|
||||
sum=0 /*initialize sum to zero. */
|
||||
|
||||
loop j=1 for q.length /*add the squares of the numerals.*/
|
||||
sum = sum + q.substr(j,1) ** 2
|
||||
end
|
||||
|
||||
if a[sum] then iterate n /*if already summed, Q is unhappy.*/
|
||||
a[sum]=1 /*mark the sum as being found. */
|
||||
q=sum /*now, lets try the Q sum. */
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue