Home Posts Tags Post Search Tag Search

Post 53

Hacker Rank 26 - Bunny Jumps

Published on: 2025-08-03 Tags: elixir, Side Project, Hacker Rank
You have a list of up to 10 bunnies and their standard jump. You need to find the position that the bunnies will all jump to at some point (smallest)

There is a built in Elixir function within the Integer module that is GCD

Integer.gcd(4, 8) = 4

There is an other mathematical standard that you can find the LCM (least common multiple) of 2 numbers by multiplying them together and then dividing by the GCD of said numbers.

We can then find the LCM of 2 of the numbers and then use that to find the LCM of all the subsequent numbers.

  def find_lowest(jumps) do
    Enum.reduce(jumps, &lcm/2)
  end
  
  def lcm(a, b), do: div(a * b, Integer.gcd(a, b))