Using the bit32 library, a possibly faster (this difference is probably not noticable), we can recreate the collatz conjecture without any division or multiplication:
local ext = bit32.extract
local bor = bit32.bor
local shift = bit32.lshift
local function collatz_conjecture(n)
if ext(n, 0) == 1 then
return bor(shift(n, 1), 1) + n
else
return shift(n, -1)
end
end
return collatz_conjecture
pros: a bit faster than traditional CC function
cons: Limited to 2^32-1 (4,294,967,295)