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?
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’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…
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?
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 :).
in that case CodeGolf is not the recommended way to start
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
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.
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.
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
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?