Skip to content

Instantly share code, notes, and snippets.

@tiagopereira17
Last active June 22, 2016 01:20
Show Gist options
  • Save tiagopereira17/120b27f95e6ab34eec55487e42107685 to your computer and use it in GitHub Desktop.
Save tiagopereira17/120b27f95e6ab34eec55487e42107685 to your computer and use it in GitHub Desktop.
The frog is located at position X and wants to get to a position greater than or equal to Y. The frog always jumps a fixed distance, D. Count the minimal number of jumps that the frog must perform to reach its target.
public class FrogJump {
public int countJumps(int X, int Y, int D) {
if(X > Y) {
return 0;
}
return (int) Math.ceil((Y - X) / (double) D);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment