Merge pull request #226 from chirag2506/SnakeLadderBoardPathJavaCode

Added my profile into readme.md and added a JAVA code
This commit is contained in:
Josh Cunningham 2018-10-09 08:42:43 -07:00 committed by GitHub
commit bc286ff7df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View File

@ -392,6 +392,13 @@ Please note that this project is released with a [Code of Conduct](CODE_OF_CONDU
- Lover of programming, drums, cars, ping-pong and anime. - Lover of programming, drums, cars, ping-pong and anime.
- [![github-alt][github-img]](https://github.com/costassolla) - [![github-alt][github-img]](https://github.com/costassolla)
### Chirag Gupta
- First Year Student
- Interested in development, machine learning.
- Lover of programming, Greek mythology, Marvel.
- [![github-alt][github-img]](https://github.com/chirag2506)
[![twitter-alt][twitter-img]](https://twitter.com/chiraggupta2506)
### CohheeTime ### CohheeTime
- I built my first website in 1999 - I built my first website in 1999

37
code/BoardPath.java Normal file
View File

@ -0,0 +1,37 @@
import java.util.ArrayList;
import java.util.Scanner;
public class getBoardPath {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
System.out.println("Enter Current Position:");
int n1= scn.nextInt();
System.out.println("Enter Destination Position:");
int n2= scn.nextInt();
System.out.println(GetBoardPath(n1, n2));
}
public static ArrayList<String> GetBoardPath(int curr, int end) {
// Returns all snake & ladder board paths from curr to end
if (curr == end) {
ArrayList<String> basePositive = new ArrayList<>();
basePositive.add("\n");
return basePositive;
}
if (curr > end) {
ArrayList<String> baseNegative = new ArrayList<>();
return baseNegative;
}
ArrayList<String> MyResult = new ArrayList<>();
for (int dice = 1; dice <= 6; dice++) {
ArrayList<String> RecResult = GetBoardPath(curr + dice, end);
for (String RecResultString : RecResult) {
MyResult.add(dice + RecResultString);
}
}
return MyResult;
}
}