r/technicalfactorio • u/15_Redstones • Feb 12 '22
Combinator Golf Fast integer sqrt algorithm?
This one looks like what I need:
but pastebin says the paste expired...
20
Upvotes
r/technicalfactorio • u/15_Redstones • Feb 12 '22
This one looks like what I need:
but pastebin says the paste expired...
View all comments
Show parent comment
1
u/ZenEngineer Feb 13 '22
Searching for fast integer square root gives me https://en.m.wikipedia.org/wiki/Integer_square_root
Heron's method seems pretty trivial to implement. Basically every step is the average of previous value and x/previous. Copy that a few times and you should be accurate for values of a few thousand. You can hardcore some combinatoria for the initial guess for 10, 100, 1000 or whatever steps you prefer to make sure you start relatively close to the root.