Anonymous user
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
do
if $.n then leave /*sequence been generated
$$=$$'-'n; $.n=1 /*add number to sequence
end
if j==maxL then do /*sequence equal to max so far ? */
end
else if j>maxL then do /*have found a new best sequence.*/
seeds=seed; maxL=j; maxnums=n
max$$=
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
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
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
|