Question: need this in SCALA LANGUAGE * The frog is on the line at position 0. * It is necessary to implement an algorithm for returning

need this in SCALA LANGUAGE

* The frog is on the line at position 0.

* It is necessary to implement an algorithm for returning the frog home to position `x`.

* The frog can move in a straight line only with a limited set of actions:

1) jump forward exactly `a` positions (i -> i + a)

* 2) jump back exactly `b` positions (i -> i - b)

* 3) you can not jump back 2 times in a row

* 4) you can not jump to forbidden positions in the `forbidden` array

In the `minimumJumps` method, return the minimum number of actions needed for the frog to get home.

* If it is impossible to return home, then return -1. */

code:

object MinimumJumpsProblem {

def minimumJumps(forbidden: Array[Int], a: Int, b: Int, x: Int): Int = {

???

} }

Test Cases: object MinimumJumpsTests {

import MinimumJumpsProblem.minimumJumps

def test1(): Unit = assert(minimumJumps(Array(14,4,18,1,15), 3, 15, 9) == 3) // 0 -> 3 -> 6 -> 9

def test2(): Unit = assert(minimumJumps(Array(8,3,16,6,12,20), 15, 13, 11) == -1) // not possible

def test3(): Unit = assert(minimumJumps(Array(1,6,2,14,5,17,4), 16, 9, 7) == 2) // 0 -> 16 -> 7

def test4(): Unit = assert(minimumJumps(Array(998), 999, 1000, 1000) == 1998) // 0 -> ... -> 2997 -> ... -> 1000 }

need this only in SCALA

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!