lua-users home
lua-l archive

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


Also you can avoid the ::a:: label and goto, using a finite for loop 
Or use the basic "calculator" interface to reduce the program only to the evaluation of the convergent series (as a single _expression_ of x, the previous value of the series, and C). And then you don't need your program to perform an explicit loop or trailing recursive call.

In all cases you need an environment where you'll run the Lua engine and can provide the UI to enter your "program" and the value of C; printing does not have to be part of the program itself as the environment can do that itself. 


Le ven. 28 juin 2019 à 00:51, Philippe Verdy <verdy_p@wanadoo.fr> a écrit :
That's because your "log" function is inexact (use an integer log2 that extracts just the exponent part of the number instead of math.log)
And you did not use the modulo2 trick to make exact divisions, so there's an imprecision on the last bit.

Le ven. 28 juin 2019 à 00:46, Xavier Wang <weasley.wx@gmail.com> a écrit :


Egor Skriptunoff <egor.skriptunoff@gmail.com> 于2019年6月28日周五 上午5:39写道:
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.


I have tried these tricks (just before your advice), but I only get a 51 byte solution:
x=1l=math.log::a::x=(l(C)+x)/(l(x)+1)print(x)goto a

and doesn't have any improve after that :-(

--
regards,
Xavier Wang.