lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


But I showed that the program can end in a predictable very short time, without printing an infinite sequence or having to wait for an infinite amount of time.

And the statement to print the result can be a single "=" in the Lua console, followed by a single _expression_ which uses a small limited number of trailing recursions. If your program loops infinitely, and prints an infinite list then it uses a self reference to itself (we have to know the name by which it can be referenced, meaning that its own name is predefined as a visible symbol like "f" in the "global" scope where you just define the code, and to print someting it needs a symbol like "o" for "out" for the function that will print something before recursing to itself by a trainling function call to that name with some computed parameters).

But as you don't want us to use "return", this program will never terminate and will loop infinitely in trailing calls, even if it has reached the maximum precision (which is then a stupid program). Add just a few bytes (6 or 7 for "return" or "return ", and 3 bytes for "o x"), then you have a clean useful program that will no longer loop infinitly and will return a response very fast (with just a few trailing recursions).





Le jeu. 27 juin 2019 à 23:39, Egor Skriptunoff <egor.skriptunoff@gmail.com> a écrit :
On Wed, Jun 26, 2019 at 11:47 PM Egor Skriptunoff wrote:
Global variable "C" contains numeric value > 15.5
The solution of math equation x^x=C must be printed
Your code must fit into 36 bytes
Dirty tricks are allowed


Some sort of codegold-related cheating is required to solve this task, so I should tell more about "dirty tricks".

Dirty trick #1:
   Please note that the task doesn't require that your program should exit after the job is done.
   The program might exit, but it doesn't have to.

What should we do if a program never stops?
Just wait until you runs out of patience and then kill the process.
My own patience lasts for 3 seconds :-)

Dirty trick #2:
   The task says that "the solution must be printed".
   But it wasn't required that your program should print only one number.

What should we do if a program prints a lot of text?
Just ignore the "invisible" text scrolled up beyond the screen.

These tricks are unfair, but they save several bytes of code.
With these tricks allowed, you can write a program which simply prints infinite sequence of numbers converging to the correct answer.
First lines of output would contain incorrect values, but later the old values would be scrolled up and replaced with more correct approximations.
At the moment when the program is killed, the whole screen would contain the correct answer on every line.


My program prints some sequence of numbers converging to the root of equation x^x=C.
Your task is either to write similar program which runs endlessly
or to print the root calculated using some other approach.

Now, with the "dirty tricks" explained, the task become quite solvable.