Laudrup18 Lv 1
good recipe
good recipe
Hey Bravo, you could replace your remove_duplicates function like this:
u=(function(t)table.sort(t)for i=#t,2,-1 do t[i]==t[i-1]and table.remove(t,i)end return t end){"a","b","a","c","b","d"}
If the table is already sorted, you don't need the table.sort(t) call.
Of course, it's much less readable, but I had fun finding it.
Also, you could remove the need for local variables in this:
local Base = band.GetResidueBase(i)
local End = band.GetResidueEnd(i)
-- local length = band.GetLength(i)
-- print(string.format(" %.5f" , length))
-- Average distance between atoms on back bone in fold.it 1.330688909
-- Std. Dev. is 0.007942111
-- base before end to keep Terminals sorted
table.insert(Terminals, Base)
table.insert(Terminals, End)
with this:
– base before end to keep Terminals sorted
table.insert(Terminals,band.GetResidueBase(i))
table.insert(Terminals,band.GetResidueEnd(i))
Those kinds of changes removes the need for Lua to allocate/deallocate storage for the local variables. Should run a little faster.
this code was not properly cleaned up and was just a proof of concept to share. it does contain dead variables and commented out code lol. "local distances = {}" is never actually used…
i am not an expert at lua or coding in general. how much time does it save? i did notice the recipe is a little slow but i figured that was the fold.it environment not the lua side. i run on a low memory computer so memory allocation is a big concern for me so i was just trying to protect that.
copilot AI says "Locals are lexical (block-scoped) and stored in the function’s stack frame, not the heap". they only declare the variable once and just re-assign them not re-declare them at run time.
Garbage cleanup was a big concern for me when developing this function. I will mess around with your suggestions and try out some stuff to make it more efficient.
the "band.AddBetweenSegments(i, i + 1, 3, 1)" which is the soul of the recipe seems to be the largest time sink. fold.it is tricky because the os.clock time for this recipe can vary from .05 seconds to 2.1 seconds just rerunning the same code.
This version gives false positives with existing cuts.