30
3
Write the shortest code that will take any real number greater than 1 as input and will output its positive inverse factorial. In other words, it answers the question "what number factorial is equal to this number?". Use the Gamma function to extend the definition for factorial to any real number as described here.
For example:
input=6 output=3
input=10 output=3.390077654
because 3! = 6
and 3.390077654! = 10
Rules
- It is forbidden to use built in factorial functions or gamma functions, or functions that rely on these functions.
- The program should be able to calculate it to 5 decimal digits, with the theoretical ability to calculate it to any precision (It should contain a number that can be made arbitrary big or small to get arbitrary precision)
- Any language is allowed, shortest code in characters wins.
I made a working example here. Have a look.
I think the last digit of
– Adám – 2017-12-05T10:33:12.983input=10 output=3.390077654
should be a1
. Try it online!2This could use some more test cases, in particular to cover zero and negative inputs. – Peter Taylor – 2014-03-05T16:43:20.207
I edited that the input should be greater than 1 because otherwise there could be muliple answers. – Jens Renders – 2014-03-05T16:45:10.180
1There can be multiple answers anyway unless you also add a requirement that the output must be greater than 1. – Peter Taylor – 2014-03-05T17:11:27.987
Your working example gives 3.99999 when inputted 24. So is such a solution acceptable? – rubik – 2014-03-05T20:07:03.590
yes because this can be seen as 4, to 5 decimal places correct – Jens Renders – 2014-03-05T20:11:20.910
Question: does code have to take input & print output, or can it just define a function that works as defined? Also how are characters counted: including whitespace (matters for python indentation) or no? – Claudiu – 2014-03-05T20:13:56.820
It must take input and output as stated above, and whitespace will be counted as this is an important part of the code. (if not, delete the whitespace) – Jens Renders – 2014-03-05T20:16:33.080
Is there any time constraints on this? – Cruncher – 2014-03-06T15:37:23.650
I will choose a winner 7 days after I posted it, I will include this in the post! – Jens Renders – 2014-03-06T16:33:38.493