Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * @author Mat
- */
- package problem.pkg11;
- public class Problem15 {
- public static void main(String[] args) {
- final int MAXNUM = 21;
- long[][] array = new long[MAXNUM][MAXNUM];
- // set numbers to 1 around "at pos
- for (int i = 0; i < MAXNUM; i++) {
- for (int j = 0; j < MAXNUM; j++) {
- array[0][j] = 1;
- }
- array[i][0] = 1;
- }
- //Work out Pascal's triangle.
- for (int i = 1; i < MAXNUM; i++) {
- for (int j = 1; j < MAXNUM; j++) {
- array[i][j] = array[i][j - 1] + array[i - 1][j];
- }
- }
- // print out array for debugging with smaller numbers
- /*
- for(int i = 0; i < MAXNUM;i++){
- for(int j = 0; j < MAXNUM;j++){
- System.out.printf("%d\t", array[i][j]);
- }
- System.out.println();
- }
- */
- System.out.println("The number of routes on a 20x20 board is "
- + array[MAXNUM - 1][MAXNUM - 1]);
- }
- }
- /* Output
- * The number of routes on a 20x20 board is 137846528820
- */
Advertisement
Add Comment
Please, Sign In to add comment