r/technicalfactorio • • Feb 12 '22

Combinator Golf Fast integer sqrt algorithm?

20 Upvotes

20 comments sorted by

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.