Power of Thor - Codesize - Puzzle discussion

I need 150+ characters to even parse the input numbers in Java. Could you share some ideas on how to parse the input in shorter code?

Don’t try to parse input.

4 Likes

As Plopx said: don’t try to parse the input. And think about what inputs you actually need.

@Plopx: You also need 66 characters of Java stuff (class definition, method signature, etc) around your actual logic, don’t you?

@Plopx @wickedjester

I was assuming that the coordinates of the light power and the initial position of Thor are necessary.

Could you give some hints on how the problem could be solved without even knowing these numbers? Or do you just use the input to distinguish between test cases and then return hardcoded answers?

As far as I know you need to at least distinguish between test cases. And then it’s hard coded, yes. Although I have a complete solution with (probably not fully optimized) 284 characters as well :wink:

49 are enough :wink:

(/me wonders why so much people want to use Java, it’s one of the most boring language for golfing)

1 Like

49? No way! o.O(darn…)

Well, Java was just my first language to start with (since it’s the one I know best). And now there are too many with less characters to call it a day :wink:

Thanks for the reply.

I confirm Plopx statement, 49 is enough , other stuff is your logic :slight_smile:

1 Like

Please add more testcases and re run all submissions.
I want to see how many people’s solution breaks

I got away with some weird stuff like not incrementing thor’s y postion
More testcases would really be amazing.

7 Likes

@Plopx, @PouletRoti: I think I got it - I counted my “throws exception” as well. Without that I have even less than 49 characters :wink: But you have to deal with that IOException somehow, don’t you?

My code size is 137 in C++.
the smallest codes are public? I would like to see how someone have got the 82 bytes of code in C++ and compare it to my code.

No codes are public for now, and especially the smallest one, because if you have it, why not copy paste to be first too?

I’m new here, there are some type of temporary competition with public write-ups after competition?

PD: I get a code of 129 chars :smiley: Maybe getting the smallest possible size is not useful, but is funny.

Nope no IO exceptions for me.

Hi, destructuring assignment seems to work only in ES6, how did you make it run in puzzles?

Javascript on CodinGame is executed in SpiderMonkey, Firefox javascript engine. If something works in Firefox, it works on CodinGame. For destructuing assignement it’s like this:

var [a, b] = '10 25'.split(' ');

Hello, there is something I can’t explain with Javascript can someone help me ?

In my code I increment/decrement Thor’s position after printing thhe solution to keep track of Thor’s moves, something like :

var inputs = readline().split(' ')
// do stuff...
while(true){
    print(...);

    if (condition) {
        inputs[1]++;
    } else if (otherCondition) {
        inputs[1]--;
    }
}

While this kind of approach seems to work well with Ruby - with loop do - in JavaScript the content of the while(true) loop is executed 200 times between each print(…). So the position of Thor is not accurate at all after the first move.

1 Like

Using a little bit of trigonometry, the walk of thor can be rendered in better way.

In my solution I calculate the azimuth between the current position of thor and the target, then I round the azimut to eights of 2PI so the direction of the step is more visually straight.
Not requested, but more correct and visually better.

1 Like

I wonder how they got lower than 107 in Python3… :confused: