For some languages, I am just curious how there can be a big gap between the top players in code size.
I hope random behavior is not used. ex: instead of reading input, one can just generate a random number and run the program hundreds/thousands of times until one run passes.
As for me, I use magic numbers which is always based on the input. It would be nice if CG team can make it clear what skills are allowed in the code golf.
If it works it’s allowed. Yes some people use random and yes some people call other language. You can even use special character (e.g. (%w([¡š #8[#M[) in ruby)…
Don’t put too much times in code golf it’s not really interesting.
In my opinion, a solution that works must be a solution repeatable - which is also one of testing principles. In this sense, a solution with ‘random behavior’ can’t be really qualified as a solution works. And it’s rather easy to prevent this kind of solution, ex: re-run the tests every day - even a weekly re-run is enough.
Anyway, thanks for the info, at least I know in some cases maybe I should stop searching vainly to optimize with ‘normal’ means
As to code-golf itself, I do get fun out of it – usually I have to study the problem in different perspectives every time I want to optimize it. And, it’s amazing to realize finally there exists so many ways of solving a problem.
Surely code-golf is not supposed to be used in real serious projects but as a game I find it’s quite funny.
Quite a pity that by doing this, golfing of a language actually turns into a dummy of another language.
The real disturbing experience for me was that I did believe other people had a much better way of solving the problem (normally that’s an exciting thing for me). But after spending some time, I realized that some practices are allowed by CG and the searches turned out to be useless.
I believe the same thing may happen to other coders which will become actually an annoying waste of time instead of pleasure. I really hope CG will do something on that.
I have pretty nice scores with thor in several languages. And I confirm that all of them are feasible with pure supposed language and no random numbers. Hope this info is useful.
I’m not sure if any top solutions contains any random. And for languages like ruby, python, perl, python3 (and maybe some more languages), you don’t need to use bash. But you just can’t be shorter than a “bashed solution” in C and C++ for example.
I can’t tell for other but my 53 character thor contains random.
You can do better without random
system() is disabled. I don’t know for the other cases.
Could someone explain what is meant by both ‘random’ and ‘magic number’ in the context of this discussion please? Thnx
For thor there is only 4 solutions to verify so you can easily harcode it.
This solution can be simplified for exemple instead of 4 output your code got only 2 differents output.
Random can be use to avoid read input and use one of this 2 solutions.
Magic number can be one of the number of the read input instead read and parse all the input.
Take thor for example - let’s say we keep only the first two tests for this example:
test 1: input = “7 8 28 8” (thor will go west)
test 2: input = “5 17 5 4” (thor will go south)
In a “normal” implementation, usually we track the positions of thor and light, we compare them, we check the boundary conditions, we may even model the problem in a N-dimension manner for pleasure
In a ‘magic number’ implementation, we may do:
flag = readline() ==“7”
while 1: print(flag? “W” : “S”)
Note: this implementation is repeatable thus stable for given tests.
In a ‘random number’ implementation, we may do:
flag = rand_int() == 7
while 1: print(flag? “W” : “S”)
As CG only records the best run, it’s enough if one run is okay when we launch the above code hundreds of times.
OK, thanks for the info, (never would of thought of randomising, all those boring submit clicks!)
Reverer your score is 58!! Are you constructing strings with RegEx or something? I can’t see many other ways to get the code shorter.
Besides, I believe the random guys are ‘clever’ enough to use robot-software to do the click/back stuff automatically instead of manually