Skip to main content
added 12 characters in body
Source Link
user25169
user25169

Lua - 141 135 139 135

function s(n)a,b={1},{1[0]=0}for i=2i=1,n do k=b[i-1]-i c=k+i+i if(k>0)and(a[k]==nil)then b[i],a[k]=k,1 else b[i],a[k+i+i]=k+i+ia[c]=c,1 end end return b end

readable version:

function s(n)
a,b={1},{1[0]=0}
for i=2i=1,n do 
   k=b[i-1]-i 
   c=k+i+i
   if (k>0) and (a[k]==nil) then 
      b[i],a[k]=k,1 
   else 
      b[i],a[k+i+i]=k+i+ia[c]=c,1
   end 
end 
return b 
end

I use 2 tables, the first one is called a and it is built so that a[i]=1 iff i has already appeared in the sequence, nil otherwise, while the second table actually holds the sequence

Lua - 141 135

function s(n)a,b={1},{1}for i=2,n do k=b[i-1]-i if(k>0)and(a[k]==nil)then b[i],a[k]=k,1 else b[i],a[k+i+i]=k+i+i,1 end end return b end

readable version:

function s(n)
a,b={1},{1}
for i=2,n do 
   k=b[i-1]-i 
   if (k>0) and (a[k]==nil) then 
      b[i],a[k]=k,1 
   else 
      b[i],a[k+i+i]=k+i+i,1
   end 
end 
return b 
end

I use 2 tables, the first one is called a and it is built so that a[i]=1 iff i has already appeared in the sequence, nil otherwise, while the second table actually holds the sequence

Lua - 141 135 139 135

function s(n)a,b={1},{[0]=0}for i=1,n do k=b[i-1]-i c=k+i+i if(k>0)and(a[k]==nil)then b[i],a[k]=k,1 else b[i],a[c]=c,1 end end return b end

readable version:

function s(n)
a,b={1},{[0]=0}
for i=1,n do 
   k=b[i-1]-i 
   c=k+i+i
   if (k>0) and (a[k]==nil) then 
      b[i],a[k]=k,1 
   else 
      b[i],a[c]=c,1
   end 
end 
return b 
end

I use 2 tables, the first one is called a and it is built so that a[i]=1 iff i has already appeared in the sequence, nil otherwise, while the second table actually holds the sequence

Source Link
user25169
user25169

Lua - 141 135

function s(n)a,b={1},{1}for i=2,n do k=b[i-1]-i if(k>0)and(a[k]==nil)then b[i],a[k]=k,1 else b[i],a[k+i+i]=k+i+i,1 end end return b end

readable version:

function s(n)
a,b={1},{1}
for i=2,n do 
   k=b[i-1]-i 
   if (k>0) and (a[k]==nil) then 
      b[i],a[k]=k,1 
   else 
      b[i],a[k+i+i]=k+i+i,1
   end 
end 
return b 
end

I use 2 tables, the first one is called a and it is built so that a[i]=1 iff i has already appeared in the sequence, nil otherwise, while the second table actually holds the sequence

Lua - 141 135

function s(n)a,b={1},{1}for i=2,n do k=b[i-1]-i if(k>0)and(a[k]==nil)then b[i],a[k]=k,1 else b[i],a[k+i+i]=k+i+i,1 end end return b end

Lua - 141 135

function s(n)a,b={1},{1}for i=2,n do k=b[i-1]-i if(k>0)and(a[k]==nil)then b[i],a[k]=k,1 else b[i],a[k+i+i]=k+i+i,1 end end return b end

readable version:

function s(n)
a,b={1},{1}
for i=2,n do 
   k=b[i-1]-i 
   if (k>0) and (a[k]==nil) then 
      b[i],a[k]=k,1 
   else 
      b[i],a[k+i+i]=k+i+i,1
   end 
end 
return b 
end

I use 2 tables, the first one is called a and it is built so that a[i]=1 iff i has already appeared in the sequence, nil otherwise, while the second table actually holds the sequence

Source Link
user25169
user25169

Lua - 141 135

function s(n)a,b={1},{1}for i=2,n do k=b[i-1]-i if(k>0)and(a[k]==nil)then b[i],a[k]=k,1 else b[i],a[k+i+i]=k+i+i,1 end end return b end