Hurkle problem (352)

Back to General discussions forum

Zacharias     2026-01-04 14:59:17

Hi. I've implemented the game and it runs smoothly on my machine (using the JITLua program). However, when I run it on the C.A. site, it yields "lost" in the answer box, right after the "ready" part. Not sure why this is happening and if I'm supposed to interact with the box somehow. As I mentioned earlier, the script works fine on my computer. Thanks

ecolog_veteran     2026-01-04 17:13:40
User avatar

I think the problem might be here:

local x = io.read('*n')
local y = io.read('*n')
if x and y then
    x = tonumber(x)
    y = tonumber(y)
    ...
endif

io.read('*n') already returns an integer, so you may not want to cast the result of this function using tonumber.

Also, some solutions insert math.randomseed(os.time()) somewhere in the beginning. I don't think it's required but it won't hurt either.

Additionally, try removing this if x and y check altogether.

Zacharias     2026-01-05 07:25:44

I see. Many thanks for your feedback! Lua is still new to me, but I'm learning. I'll revise my code later. Thanks

Rodion (admin)     2026-01-06 10:56:47
User avatar

Hm, this thread reminded me of some amendment I made for Lua interpreter a couple of months ago - it was to address the lack of compound assignment, unusual inequality operator (I remember our colleague Clive expressed our common feeling of how confusing these are) and perhaps something else. It seems like the amended version is used in the "browser version" of Lua on this site, but not in the "Sandbox" yet. So let this be a note to me to update the latter too.

Please login and solve 5 problems to be able to post at forum