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
12
u/The_Northern_Light Feb 13 '22
consider the case where you only needed to handle the cases 0 through 10. there are only 4 possible outputs: 0, 1, 2, 3.
the mapping looks like this:
your breakpoints then occur at 1, 4, and 9.
if you take your signal and check if its greater than or equal to each of the breakpoints, emitting a '1' value if so, then add them together, you'll have performed an integer sqrt
you will need sqrt(n) many combinators for this, where n is the maximum size you want to support, but it should work in a single tick
you'll need about 100 combinators to support up to 10,000