C++ Frog Jmp
#include <cmath>
long long frogJmp(long long x, long long y, long long d)
{
return static_cast<long long>(std::ceil(static_cast<double>(y - x) / d));
}
This computes the jump count with math instead of simulation, which is the cleanest way to solve it.
C# Frog Jmp
static long FrogJmp(long x, long y, long d)
{
return (long)Math.Ceiling((double)(y - x) / d);
}
This computes the jump count with math instead of simulation, which is the cleanest way to solve it.
Elixir Frog Jmp
defmodule FrogJmp do
def frog_jmp(x, y, d), do: ceil((y - x) / d)
end
This computes the jump count with math instead of simulation, which is the cleanest way to solve it.
Erlang Frog Jmp
-module(frog_jmp).
-export([frog_jmp/3]).
frog_jmp(X, Y, D) ->
(Y - X + D - 1) div D.
This computes the jump count with math instead of simulation, which is the cleanest way to solve it.
Go Frog Jmp
func frogJmp(x, y, d int) int {
return int(math.Ceil(float64(y-x) / float64(d)))
}
This computes the jump count with math instead of simulation, which is the cleanest way to solve it.
Haskell Frog Jmp
frogJmp :: Int -> Int -> Int -> Int
frogJmp x y d = ceiling (fromIntegral (y - x) / fromIntegral d :: Double)
This computes the jump count with math instead of simulation, which is the cleanest way to solve it.
Java Frog Jmp
public class Solution {
public static long frogJmp(int x, int y, int d) {
return (long) Math.ceil(((double) y - x) / d);
}
}
This computes the jump count with math instead of simulation, which is the cleanest way to solve it.
Lisp Frog Jmp
(defun frog-jmp (x y d)
(ceiling (- y x) d))
This computes the jump count with math instead of simulation, which is the cleanest way to solve it.
PHP Frog Jmp
function frogJmp(int $x, int $y, int $d): int
{
return ceil(($y - $x) / $d);
}
This computes the jump count with math instead of simulation, which is the cleanest way to solve it.
Python Frog Jmp
import math
def frog_jmp(x: int, y: int, d: int) -> int:
return math.ceil((y - x) / d)
This computes the jump count with math instead of simulation, which is the cleanest way to solve it.