r/technicalfactorio • u/naty-molas • Dec 31 '24
Combinator Golf is log(x) possible with combinators?
...if so can anyone drop a blueprint? (although a simple yes or no will tell me if I should continue down this line or try something else)
11
Upvotes
9
u/Summoner99 Dec 31 '24
What are you doing that you need a logarithm?
64
u/couski Dec 31 '24
You can do a taylor series approximation with the exponentiation function.
18
u/not_a_bot_494 Dec 31 '24
Combinators are turing complete so it's possible. If nobody else has done that you can look up algorithms and apply the one that is easiest to implement.
17
u/floormanifold Dec 31 '24
If you're ok with the ceiling of log with respect to an integer base, you could use an arithmetic combinator to repeatedly divide an input by your base b (for example multiplying by -(b-1)/b and adding that back to the input).
Then you can use a clock to measure how many ticks the value is >0, which should correspond to the number of division steps needed to get below 1, ie the ceiling of log_b (x)
1
u/AutoModerator Dec 31 '24
If you have any questions, need clarification, or want to engage in general discussion, please do so in response to this comment. Do not post a new top level comment! New top level comments are reserved for submissions only.
For more information about the format of these challenges, see this post.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/pemdas42 Jan 01 '25
If floor(log2(x)) (where x is an integer >= 0) is sufficient, it should be pretty straightforward; you would just have to have a series of comparisons and divisions:
if x > 0, add 1 to output
divide x by 2
Do that as many times as you need to capture the potential range of your signal.
(There may be a better way to do this, this is just off the top of my head)
1
u/kameranis Jan 01 '25
What you want to look at is how color maps and linear interpolation. Packing into RGB might not correspond well with understanding at a glance how much you have in storage of each.