Quickest way up - Coding question

profilejackyjacky

Need java coding for the snake and ladder game question.

Also need to fulfill the input and output. The due date is Today 12pm. Thanks.

2

3

32 62

42 68

12 98

7

95 13

97 25

93 37

79 27

75 19

49 47

67 17

4

8 52

6 80

26 42

2 72

9

51 19

39 11

37 29

81 3

59 5

79 23

53 7

43 33

77 21

Sample Output

3

5

Explanation

For the first test: To traverse the board via the shortest route, the player first rolls the die to get a 5, and ends up at square 6. He then rolls the die to get 6. He ends up at square 12, from where he climbs the ladder to square 98. He then rolls the die to get '2', and ends up at square 100, which is the target square. So, the player required 3 rolls of the die for this shortest and best case scenario. So the answer for the first test is 3. 

    • 8 years ago
    • 15
    Answer(0)