Summarize and say sequence: Difference between revisions

m
→‎{{header|REXX}}: changed program to use sparse arrays instead of the <tt> wordpos </tt> bif, and also other cosmetic changes. -- ~~~~
(→‎{{header|REXX}}: added the REXX language. -- ~~~~)
m (→‎{{header|REXX}}: changed program to use sparse arrays instead of the <tt> wordpos </tt> bif, and also other cosmetic changes. -- ~~~~)
Line 1,624:
<lang rexx>/*REXX program to generate a self-referential sequence and list the maxs*/
 
parse arg low high .; maxL=0; seeds=; max$$=
if low=='' then low=1 /*no low? Then use the default*/
if high=='' then high=1000000 /*no high? " " " " */
/*──────────────────────────────────────────────────traipse through #'s.*/
do seed=low to high; n=seed; $.=0; $$=n; $.n=1
 
do j=1 until x==n /*generate interation sequence. */
do seed=low to high
n x=seedn; $= n=
do jk=9 to 0 by -1 until x==n /*gen new sequence*/
x _=ncountstr(k,x); if _\==0 then n=n||_||k
do k=9 to 0 by -1end
if $.n then leave /*sequence been generated _=countstr(k,x); if _\==0 then n=n||_||kbefore?*/
$$=$$'-'n; $.n=1 /*add number to sequence end& roster*/
end
 
if j==maxL then do /*sequence equal to max so far ? */
if wordpos(n,$)\==0 then leave
$ seeds=$seeds seed; maxnums=maxnums n
end max$$=max$$ $$
 
if j==maxL then do
seeds=seeds seed; maxnums=maxnums n
max$=max$ translate(strip($),'-'," ")
end
else if j>maxL then do /*have found a new best sequence.*/
seeds=seed; maxL=j; maxnums=n
max$$=translate(strip($),'-'," ")$
end
end
/*───────────────────────────────────────────────────display the output.*/
 
say 'seeds that had the most iterations =' seeds
hdr=copies('=',30); say 'maximum sequence length =' maxL
 
do j=1 for words(max$$); say
say copies('=',maxL)hdr "iteration sequence for: " word(maxseedsseeds,j) ' ('maxL "iterations)"
w=word(max$$,j)
q=translate(w,,'-')
do k=1 for words(q);
Line 1,666 ⟶ 1,665:
maximum sequence length = 21
 
============================== iteration sequence for: 9009 MAXSEEDS (21 iterations)
9009
2920
Line 1,689 ⟶ 1,688:
19182716152413228110
 
============================== iteration sequence for: 9090 (21 iterations)
9090
2920
Line 1,712 ⟶ 1,711:
19182716152413228110
 
============================== iteration sequence for: 9900 (21 iterations)
9900
2920