3 improved score
source | link

Lua, 242 228 226226 211 bytes

s={}u={}i=0 n=0+...while i<n do
n=n-i
x,S=1,0
for j=1,i do
while u[x]do x=x+1 end
s[j]=x
S=S+x
u[x]=0
end
while u[x]or p do
x=x+1
d=S+x
p=F
for c=2,d-1 do
if d%c<1p=p thenor p=0;break;endd%c<1
end
end
i=i+1
s[i]=x
u[x]=0
end
print(s[n])

Try it online!Try it online!

Lua, 242 228 226 bytes

s={}u={}i=0 n=0+...while i<n do
n=n-i
x,S=1,0
for j=1,i do
while u[x]do x=x+1 end
s[j]=x
S=S+x
u[x]=0
end
while u[x]or p do
x=x+1
d=S+x
p=F
for c=2,d-1 do
if d%c<1 then p=0;break;end
end
end
i=i+1
s[i]=x
u[x]=0
end
print(s[n])

Try it online!

Lua, 242 228 226 211 bytes

s={}u={}i=0 n=0+...while i<n do
n=n-i
x,S=1,0
for j=1,i do
while u[x]do x=x+1 end
s[j]=x
S=S+x
u[x]=0
end
while u[x]or p do
x=x+1
d=S+x
p=F
for c=2,d-1 do
p=p or d%c<1
end
end
i=i+1
s[i]=x
u[x]=0
end
print(s[n])

Try it online!

2 deleted 34 characters in body; added 9 characters in body
source | link

Lua, 242242 228 226 bytes

s={}u={}i=0 n=0+...forwhile i=1,ni<n do
n=n-i
x,S=1,0
for j=1,i-1 do
while u[x]do x=x+1 end
s[j]=x
S=S+x
u[x]=0
end
while u[x]or p do
x=x+1
d=S+x
p=nilp=F
for c=2,d-1 do
if d%c<1 then p=0;break;end
end
end
i=i+1
s[i]=x
u[x]=0
if n<=i then end
print(s[n])break end
n=n-i
end

Try it online!Try it online!

Lua, 242 bytes

s={}u={}n=0+...for i=1,n do
x,S=1,0
for j=1,i-1 do
while u[x]do x=x+1 end
s[j]=x
S=S+x
u[x]=0
end
while u[x]or p do
x=x+1
d=S+x
p=nil
for c=2,d-1 do
if d%c<1 then p=0;break;end
end
end
s[i]=x
u[x]=0
if n<=i then print(s[n])break end
n=n-i
end

Try it online!

Lua, 242 228 226 bytes

s={}u={}i=0 n=0+...while i<n do
n=n-i
x,S=1,0
for j=1,i do
while u[x]do x=x+1 end
s[j]=x
S=S+x
u[x]=0
end
while u[x]or p do
x=x+1
d=S+x
p=F
for c=2,d-1 do
if d%c<1 then p=0;break;end
end
end
i=i+1
s[i]=x
u[x]=0
end
print(s[n])

Try it online!

1
source | link

Lua, 242 bytes

s={}u={}n=0+...for i=1,n do
x,S=1,0
for j=1,i-1 do
while u[x]do x=x+1 end
s[j]=x
S=S+x
u[x]=0
end
while u[x]or p do
x=x+1
d=S+x
p=nil
for c=2,d-1 do
if d%c<1 then p=0;break;end
end
end
s[i]=x
u[x]=0
if n<=i then print(s[n])break end
n=n-i
end

Try it online!