If you wish to make it even more efficient: Let it go through the Z-axis first & construct the posit table once (before the for loops) and simply assign new x/y/z values.
local posit = { x = 0, y = 0, z = 0, stackpos = 253 }
for posz = positions['a'].z, positions['b'].z do...