Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -5,9 +5,9 @@ recamanSucc: function [seen, n, r].memoize[
|
|||
]
|
||||
|
||||
recamanUntil: function [p][
|
||||
n: new 1
|
||||
n: 1
|
||||
r: 0
|
||||
rs: new @[r]
|
||||
rs: @[r]
|
||||
seen: rs
|
||||
blnNew: true
|
||||
while [not? do p][
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. RECAMAN.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 RECAMAN-SEQUENCE COMP.
|
||||
02 A PIC 999 OCCURS 99 TIMES INDEXED BY I.
|
||||
02 N PIC 999 VALUE 0.
|
||||
|
||||
01 VARIABLES COMP.
|
||||
02 ADDC PIC S999.
|
||||
02 SUBC PIC S999.
|
||||
02 SPTR PIC 99 VALUE 1.
|
||||
|
||||
01 OUTPUT-FORMAT.
|
||||
02 OUTI PIC Z9.
|
||||
02 OUTN PIC BZ9.
|
||||
02 OUTS PIC X(79).
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
BEGIN.
|
||||
PERFORM GENERATE-NEXT-ITEM 15 TIMES.
|
||||
PERFORM COLLATE-ITEM VARYING I FROM 1 BY 1
|
||||
UNTIL I IS GREATER THAN 15.
|
||||
DISPLAY 'First 15 items:' OUTS.
|
||||
|
||||
FIND-REPEATING.
|
||||
PERFORM GENERATE-NEXT-ITEM.
|
||||
SET I TO 1.
|
||||
SEARCH A VARYING I
|
||||
WHEN I IS NOT LESS THAN N
|
||||
NEXT SENTENCE
|
||||
WHEN A(I) IS EQUAL TO A(N)
|
||||
SUBTRACT 1 FROM N GIVING OUTI
|
||||
MOVE A(N) TO OUTN
|
||||
DISPLAY 'First repeated item: A(' OUTI ') =' OUTN
|
||||
STOP RUN.
|
||||
GO TO FIND-REPEATING.
|
||||
|
||||
GENERATE-NEXT-ITEM.
|
||||
IF N IS EQUAL TO ZERO
|
||||
MOVE ZERO TO A(1)
|
||||
ELSE
|
||||
ADD N, A(N) GIVING ADDC
|
||||
SUBTRACT N FROM A(N) GIVING SUBC
|
||||
IF SUBC IS NOT GREATER THAN ZERO
|
||||
MOVE ADDC TO A(N + 1)
|
||||
ELSE
|
||||
SET I TO 1
|
||||
SEARCH A VARYING I
|
||||
WHEN I IS NOT LESS THAN N
|
||||
MOVE SUBC TO A(N + 1)
|
||||
WHEN A(I) IS EQUAL TO SUBC
|
||||
MOVE ADDC TO A(N + 1).
|
||||
ADD 1 TO N.
|
||||
|
||||
COLLATE-ITEM.
|
||||
MOVE A(I) TO OUTN.
|
||||
STRING OUTN DELIMITED BY SIZE INTO OUTS WITH POINTER SPTR.
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
local a = {[0]=0}
|
||||
local used = {[0]=true}
|
||||
local used1000 = {[0]=true}
|
||||
local count1000 = 1
|
||||
local foundDup = false
|
||||
local n = 1
|
||||
|
||||
while n<=15 or not foundDup or #used1000<1001 do
|
||||
while n<=15 or not foundDup or count1000 <1001 do
|
||||
local nxt = a[n - 1] - n
|
||||
if nxt<1 or used[nxt] ~= nil then
|
||||
nxt = nxt + 2 * n
|
||||
|
|
@ -14,7 +15,10 @@ while n<=15 or not foundDup or #used1000<1001 do
|
|||
if not alreadyUsed then
|
||||
used[nxt] = true
|
||||
if 0<=nxt and nxt<=1000 then
|
||||
used1000[nxt] = true
|
||||
if not used1000[nxt] then
|
||||
used1000[nxt] = true
|
||||
count1000 = count1000 + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
if n==14 then
|
||||
|
|
@ -28,7 +32,7 @@ while n<=15 or not foundDup or #used1000<1001 do
|
|||
print("The first duplicated term is a["..n.."] = "..nxt)
|
||||
foundDup = true
|
||||
end
|
||||
if #used1000 == 1001 then
|
||||
if count1000 == 1001 then
|
||||
print("Terms up to a["..n.."] are needed to generate 0 to 1000")
|
||||
end
|
||||
n = n + 1
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
' Recaman's sequence - vbscript - 04/08/2015
|
||||
nx=15
|
||||
h=1000
|
||||
Wscript.StdOut.WriteLine "Recaman's sequence for the first " & nx & " numbers:"
|
||||
Wscript.StdOut.WriteLine recaman("seq",nx)
|
||||
Wscript.StdOut.WriteLine "The first duplicate number is: " & recaman("firstdup",0)
|
||||
Wscript.StdOut.WriteLine "The number of terms to complete the range 0--->"& h &" is: "& recaman("numterm",h)
|
||||
Wscript.StdOut.Write vbCrlf&".../...": zz=Wscript.StdIn.ReadLine()
|
||||
|
||||
function recaman(op,nn)
|
||||
Dim b,d,h
|
||||
Set b = CreateObject("Scripting.Dictionary")
|
||||
Set d = CreateObject("Scripting.Dictionary")
|
||||
list="0" : firstdup=0
|
||||
if op="firstdup" then
|
||||
nn=1000 : firstdup=1
|
||||
end if
|
||||
if op="numterm" then
|
||||
h=nn : nn=10000000 : numterm=1
|
||||
end if
|
||||
ax=0 'a(0)=0
|
||||
b.Add 0,1 'b(0)=1
|
||||
s=0
|
||||
for n=1 to nn-1
|
||||
an=ax-n
|
||||
if an<=0 then
|
||||
an=ax+n
|
||||
elseif b.Exists(an) then
|
||||
an=ax+n
|
||||
end if
|
||||
ax=an 'a(n)=an
|
||||
if not b.Exists(an) then b.Add an,1 'b(an)=1
|
||||
if op="seq" then
|
||||
list=list&" "&an
|
||||
end if
|
||||
if firstdup then
|
||||
if d.Exists(an) then
|
||||
recaman="a("&n&")="&an
|
||||
exit function
|
||||
else
|
||||
d.Add an,1 'd(an)=1
|
||||
end if
|
||||
end if
|
||||
if numterm then
|
||||
if an<=h then
|
||||
if not d.Exists(an) then
|
||||
s=s+1
|
||||
d.Add an,1 'd(an)=1
|
||||
end if
|
||||
if s>=h then
|
||||
recaman=n
|
||||
exit function
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
next 'n
|
||||
recaman=list
|
||||
end function 'recaman
|
||||
Loading…
Add table
Add a link
Reference in a new issue