31
1
Wouldn't it be neat if programming functions could be inverted, just like the mathematical function they implement?
Write a function (or program) that takes one input x
in any form, that outputs ln(x)
.
When the bytes of the program are reordered/reversed so that the first byte now is the last byte, it should take one input x
in any form and output e^x
instead.
- Your answer must have at least 3 correct significant figures.
- Approximations are fine, as long as they have at least 3 correct significant figures.
- Your code must be in the same programming language both forwards and backwards.
Let's say this program implements ln(x)
:
abc你好
Then this program has to implement e^x
:
\xBD\xA5\xE5\xA0\xBD\xE4cba
Gold star if you use a language without float support.
This is a weird form of code-golf, so the shortest program wins.
4"Wouldn't it be neat if programming functions could be inverted, just like the mathematical function they implement?" Some languages (e.g. J and Mathematica) can actually do this for some functions. – Martin Ender – 2016-02-06T11:29:16.743
Additionally, K2 could approximate an inverse for an arbitrary monadic pure function via its "function inverse" overload of dyadic and triadic
?
, which used the secant method. – JohnE – 2016-02-06T15:19:31.9831"at least 3 correct significant figures" - over what range? – TLW – 2016-02-06T16:48:07.137
4I realize it's far too late now, but I think this would have been a really nice challenge had comments been disallowed. – Alex A. – 2016-02-06T21:45:54.207
I actually thought of that when I came up with this challenge @AlexA. but forgot about it while writing the post :P Also that would've made "normal" languages like java, c++ etc basically impossible. – Filip Haglund – 2016-02-07T12:59:00.897
@TLW a big enough range, say up to 10k? I want you to have to handle printing floats, and a 32bit int should be enough for storage. – Filip Haglund – 2016-02-07T13:00:39.703