Skip to content

Commit 6101d7f

Browse files
committed
formatting
1 parent 397b3b4 commit 6101d7f

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/main/java/com/thealgorithms/others/SnakeAndLadder.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.LinkedList;
44
import java.util.Queue;
55
import java.util.Scanner;
6+
67
// Java program to find minimum number of dice
78
// throws required to reach last cell from first
89
// cell of a given snake and ladder board
@@ -27,7 +28,6 @@ public static int getMinimumDiceThrows(int numberOfCells, int[] graph) {
2728
startingQueueEntry.distance = 0;
2829
visited[0] = 1;
2930
queue.add(startingQueueEntry);
30-
3131
//Using BFS
3232
QueueEntry currentQueueEntry = null;
3333
while (!queue.isEmpty()) {
@@ -54,7 +54,7 @@ public static int getMinimumDiceThrows(int numberOfCells, int[] graph) {
5454
return currentQueueEntry.distance;
5555
}
5656

57-
public static void main(String args[]) {
57+
public static void main(String[] args) {
5858
Scanner in = new Scanner(System.in);
5959
System.out.println("Enter number of cells in board");
6060
int numberOfCells = in.nextInt();
@@ -72,14 +72,11 @@ public static void main(String args[]) {
7272
System.out.println("Enter starting cell and ending cell of snake or ladder");
7373
int[] positions = new int[2 * n];
7474
for (int i = 0; i < n; i++) {
75-
int startingCell = in.nextInt();
76-
int endingCell = in.nextInt();
77-
positions[2 * i] = startingCell;
78-
positions[2 * i + 1] = endingCell;
75+
positions[2 * i] = in.nextInt();
76+
positions[2 * i + 1] = in.nextInt();
7977
//If there is a snake or ladder, we assign the ending position of the snake and ladder
80-
graph[startingCell - 1] = endingCell - 1;
78+
graph[positions[2 * i] - 1] = positions[2 * i + 1] - 1;
8179
}
8280
System.out.println("Minimum number of dice throws required to end the game is " + getMinimumDiceThrows(numberOfCells, graph));
83-
8481
}
8582
}

0 commit comments

Comments
 (0)