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
Anarchy golf and codingame both use stdin/stdout requirement, since they have automatic validation for their site ranking. The code golf stackexchange allows anything, since it doesn't have ranking, automatic validation, or anything like that. Its meant to be more person to person, and solutions are provided so people can learn from each other. Because of this, I feel that we should take the approach the stackexchange uses, and allow anything that isn't extremely out of the ordinary. There isn't a ranking here, and if there was people would just copy/paste the best solution, so there's really no point in forcing solutions to be easily verifiable. Additionally- while coding the solution, people can still use the automatic validation script to help them debug their solution by using stdin/stdout, and calling the function from that. Then afterwards, they call pull that section of code out.
So to be 100% clear- I have changed by mind. Functions / full programs / code blocks / etc are allowed. Thank you for bringing this up- the issue was bound to come up at some point, and this way it gets cleared up from the start.