Power of Thor - Codesize - Puzzle discussion

This puzzle can be solved without going north, please fix this

Also, test count is way too low and tests are predictable. This makes hardcoding more viable than actually solving it, which probably isn’t the intention. Please randomize tests and increase them in count. Really discouraging to see such problems, what’s the point of playing if the best option is hardcoding?

5 Likes

My Code should work but it does not… anybody know why?

var inputs = readline().split(' ');
const lightX = parseInt(inputs[0]); // the X position of the light of power
const lightY = parseInt(inputs[1]); // the Y position of the light of power
const initialTX = parseInt(inputs[2]); // Thor's starting X position
const initialTY = parseInt(inputs[3]); // Thor's starting Y position

var thorX = initialTX;
var thorY = initialTY;

while (true) {
    var remainingTurns = parseInt(readline());
    var directionX = "";
    var directionY = "";
    
    directionX = (thorX > lightX) ? "W":"E";
    thorX = (thorX > lightX) ? thorX-1:thorX+1;
    
    directionY=(thorY > lightY) ? "N":"S";
    thorY = (thorY > lightY) ? thorY-1:thorY+1;

    print(directionY + directionX);
}

I think you missed out on diagonal movements to shorten the move counts.

I think you’re missing the option to not go N/S or W/E at all. Currently, you’re always going e.g. North or South (if thorY > lightY then N else S), but what if thorY == lightY? You should neither go north nor south…

1 Like

Hi all,

I’m quite new on these code golfing challenges but I like them, I learned a ton about JavaScript :).

I would be interested to have the lowest chars count with Vanilla JS (no hack). I’m not interested about the hack stuff (using system and bash or trying to hack the system).

I’m OK with writing code that only pass tests though.

Anyone know the minimum size done with pure JS that pass all tests?

Thanks!

it is 56 for js

Thanks for your answer d-s-x!

I saw your first answers (before you edit your message twice), I wasn’t sure the system trick was shut down for JS. And I wasn’t sure your 56 chars long solution was pure JS either.

Thanks for your feedback. I have a lot to learn to reduce my code, lot of room for improvement in 2019, perfect :).

Have a nice end of year!
Jérémy.

1 Like

can someone please help me on level one. I am new in coding and i m really confused.

You have to solve the puzzle and then minify it. The objective here is to have the fewer character for you code to do the job !

new in coding

in that case CodeGolf is not the recommended way to start :smiley:

as OptiPanda said, the goal in CodeGolf is to have the smallest source code size in bytes. including comments, whitespaces, variable names, etc…
that means in this mode you will need to have a ton of obscure language tricks at your disposal, and - what’s more relevant now - will generate source code which is pretty much unreadable!

try sticking to the easy puzzles, and after solving them for yourself try to look at and understand other coder’s solutions (in the same language).

don’t be afraid to ask anything and welcome to the source :slight_smile:

2 Likes

I am not like new new to coding, i have done the basics of c,c++, and java. Its just the 2D array system and all the grid system i just dont get it. I am making a texted based RPG that needs to be in a 2D array and I am really confused on how to make the game.

Which language?

C; YT, <3min
Java: Tutorial in a blog

As to your goal: a nice Wiki article

And definitely watch Creating a rogue-like in C++, YT 40min

do you know if i want to keep track on where the hero is going on the map how should i do that?

You should calculate by yourself where is Thor.

The validators differ from the puzzle test cases to prevent hard coded solutions. This is why you can have some fails here even if all of the tests provided in the IDE have been successfully passed.its in thor easy game .it says to go south in second part when it must go north.

It could be useful if you are interested in working on one of these tools’ dev.
Coders come in all shapes and sizes !

Hi!
I’ve been trying to compact my Ruby solution.
I’ve managed to hardcode in 64 characters.
Also, I’ve made hardcode modification that picks solution on random and it’s 55 chars. It has probability of passing all tests of 0.25 * 0.25 * 0.25 * 0.25 which is 1 in 256. And I wasn’t fortunate enough yet, especially because of the limit of submissions in a row.
So, I’ve been wondering, are top solutions use random approach as well, or they just found a better way to hardcode?
Thanks in advance!

UPDATE: Yup, I did it! It took me about 220 submissions to get lucky and score 100% with random hardcoded solution! Phew, google should thank me for labeling all those busses, cars, traffic lights and fire hydrants :smiley:

2 Likes

So hardcoding is the way to go here (unfortunately). I also understand that I have to randomize it and submit it until I get lucky.

Is that correct?

picks solution on random and it’s 55 chars

My solution of 50 chars is not randomized at all. And I think there’s still room for improvement so 45 is not out of question.
Well, yes, randomized solution ultimately is the shortest but why would you submit 220 times code that is 10 charts apart from best one?

1 Like

It’s my first code length puzzle and i think it’s a good one to start but how long does the rank take to update?