Solution to Frog-Jmp by codility

15 Jan

Question: https://codility.com/demo/take-sample-test/frog_jmp

Question Name: FrogJmp

This is a very easy question. If with C, one statement is enought.

28 thoughts on “Solution to Frog-Jmp by codility

  1. ‘my solution in vb.net….

  2. Solution in C#

    • Please don’t take it personally, I just try to think loud…

      This is a perfect example where codility gives 100/100 points for a code, that runs perfectly, but has readability issues. Inappropriate usage of var is pretty subjective, I know. It’s really useful in many cases, but this is a typical situation where it has a negative effect on readability.

      Although I am not sure, how could such readability aspects be automatically checked.

      • I am not a C# expert. And I do not know the negative effect of var.

        However, I hope this community be open-minded. Any technique discussion without personal attacks is welcome!

  3. Solution in JavaScript

  4. in PHP:

  5. Quick solution for Pascal (100%)

  6. These solutions are nice, but modulo is expensive. pseudo: diff := x-y, steps := diff/d, if steps*d < diff: steps++. The multiplication is cheaper than a second division.

    • Sure, there is some space in the original solution to improve. And your suggestion is very awesome!

      PS: as long as the solution passed the test, the readability comes first, for the blog post.

  7. Why not:

  8. Your code is missing a line for no jump.

  9. PHP

  10. return (int)Math.Ceiling((Y – X) / (decimal)D);

    P.S. I just saw someone posted this solution in PHP. But still… here it is in C# 🙂

  11. My Java solution (100%)

Leave a Reply

Your email address will not be published. Required fields are marked *