Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Recamans-sequence/REXX/recamans-sequence-1.rexx
Normal file
26
Task/Recamans-sequence/REXX/recamans-sequence-1.rexx
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*REXX pgm computes a Recamán sequence up to N; the 1st dup; # terms for a range of #'s.*/
|
||||
parse arg N h . /*obtain optional arguments from the CL*/
|
||||
if N=='' | N=="," then N= 15 /*Not specified? Then use the default.*/
|
||||
if h=='' | h=="," then h= 1000 /* " " " " " " */
|
||||
say "Recamán's sequence for the first " N " numbers: " recaman(N)
|
||||
say; say "The first duplicate number in the Recamán's sequence is: " recaman(0)
|
||||
say; say "The number of terms to complete the range 0───►"h ' is: ' recaman(-h)
|
||||
exit 0 /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
recaman: procedure; parse arg y,,d.; $=0; !.=0; _=0; !.0=1 /*init. array and vars.*/
|
||||
r= y<0; Reca= 0; hi= abs(y) /*for the 2nd invoke. */
|
||||
o= y==0; if y<1 then y= 1e8 /* " " 3rd " */
|
||||
do #=1 for y-1; z= _ - # /*next # might be < 0. */
|
||||
if z<0 then z= _ + # /*this is faster than: */
|
||||
else if !.z then z= _ + # /*if !.z | z<0 then ···*/
|
||||
!.z= 1; _= z /*mark it; add to seq.*/
|
||||
if r then do; if z>hi then iterate /*ignore #'s too large.*/
|
||||
if d.z=='' then Reca= Reca + 1 /*Unique? Bump counter.*/
|
||||
d.z= . /*mark # as a new low. */
|
||||
if Reca>=hi then return # /*list is complete ≥ HI*/
|
||||
iterate
|
||||
end /* [↑] a range of #s. */
|
||||
if o then do; if d.z==. then return z; d.z=.; iterate /*check if dup #.*/
|
||||
end
|
||||
$= $ z /*add number to $ list?*/
|
||||
end /*#*/; return $ /*return the $ list. */
|
||||
46
Task/Recamans-sequence/REXX/recamans-sequence-2.rexx
Normal file
46
Task/Recamans-sequence/REXX/recamans-sequence-2.rexx
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*REXX program computes & displays the Recaman sequence */
|
||||
/*improved using version 1's method for task 3 */
|
||||
Call time 'R' /* Start timer */
|
||||
Parse Arg n
|
||||
If n='' Then n=15
|
||||
Say 'the first' n 'elements:' recaman(n)
|
||||
Say ans.2
|
||||
Say ans.3
|
||||
Say time('E') 'seconds elapsed'
|
||||
Exit
|
||||
|
||||
recaman:
|
||||
Parse Arg n /* Wanted number of elements */
|
||||
have.=0 /* Number not yet in sequence */
|
||||
e.0=0 /* First element */
|
||||
have.0=1 /* is in the sequence */
|
||||
s=0 /* Sequence to be shodn */
|
||||
done=0 /* turn on first duplicate switch */
|
||||
d.=0
|
||||
d.0=1
|
||||
dn=1 /* number of elements <=1000 */
|
||||
Do i=1 until dn==1001 /* Loop until all found */
|
||||
ip=i-1 /* previous index */
|
||||
temp=e.ip-i /* potential next element */
|
||||
If temp>0 & have.temp=0 Then /* to be used */
|
||||
Nop
|
||||
Else /* compute the alternative */
|
||||
temp=e.ip+i
|
||||
e.i=temp /* Set next element */
|
||||
If words(s)<n Then /* not enough in output */
|
||||
s=s temp /* add the element to the output */
|
||||
If temp<=1000 Then Do /* eligible for task 3 */
|
||||
If d.temp=0 Then Do /* not yet encountered */
|
||||
d.temp=1 /* Remember it's there */
|
||||
dn=dn+1 /* count of integers<=1000 found */
|
||||
End
|
||||
End
|
||||
If done=0 & have.temp=1 Then Do
|
||||
ans.2='First duplicate ('temp') added in iteration' i,
|
||||
'elapsed:' time('E') 'seconds'
|
||||
done=1
|
||||
End
|
||||
ans.3='Element number' i 'is the last to satisfy task 3. It is' temp
|
||||
Have.temp=1
|
||||
End
|
||||
Return s
|
||||
Loading…
Add table
Add a link
Reference in a new issue