r/CoderTrials • u/07734willy • Jul 08 '18
CodeGolf [Easy] Solving a Small Equation
This problem is a codegolf problem. That means the objective isn't to just solve the problem, but to do so with the smallest program size. Everything from comments, spaces, tabs, and newlines counts against you.
Background
While there certainly are some complex mathematical equations that are too difficult to solve, most of the ones using the basic mathematical operations (addition, multiplication, exponentiation...) are usually fairly easy. Especially when they they only have one variable, and one operator. However, one particularly difficult equation stands out:
x^x = kWhere ^ denotes exponentiation, and k is some constant we choose. This may look trivial to solve, and its worth taking a stab at it to convince yourself there isn't a simple way to approach this, apart from approximation.
Your task is to write a program to solve for x, to 5 decimal digits of precision, for a provided constant k.
Input
A single number- the k in x^x = k. Example:
743Output
A number, for which the x in x^x = k is accurate to 5 decimal places. For the above input, we would have:
4.43686Testcases
=========
743
4.43686
=========
97
3.58392
=========
256
4.0
=========
947
4.53387
=========
15
2.71316
=========
78974
6.18749
=========
11592.347
5.49334
=========Character Count
Use the following command to measure the size of the program, in bytes and characters:
wc -mc filename.txt
View all comments
Show parent comment
2
u/07734willy Jul 08 '18
Absolutely. Anything that isn't extremely out of the norm would be allowed. So return values, arguments, stdin/stdout are all fine. Parsing the input from a command line argument, and writing to an environment variable might cross a line, but everything that isn't too strange is fine.
Edit: actually I don't really see much of a problem with the command line argument one either, but environment variable would still be taking it to an extreme.