Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 0.79 KB | None | 0 0
  1. public static void main (string[] args) {
  2.     if (args.length != 2) {
  3.         error ("Wrong number of arguments");
  4.         return;
  5.     }
  6.  
  7.     int gridSize = int.parse(args[1]);
  8.  
  9.     if (gridSize < 0 || gridSize > 224) {
  10.         error ("Out of bounds");
  11.         return;
  12.     }
  13.  
  14.     int64[,] grid = new int64[gridSize+1, gridSize+1];
  15.  
  16.     //Initialise the grid with boundary conditions
  17.     for (int i = 0; i < gridSize; i++) {
  18.         grid[i, gridSize] = 1;
  19.         grid[gridSize, i] = 1;
  20.     }
  21.  
  22.     for (int i = gridSize - 1; i >= 0; i--) {
  23.         for (int j = gridSize - 1; j >= 0; j--) {
  24.             grid[i, j] = grid[i+1, j] + grid[i, j+1];
  25.             print (grid[i, j].to_string () + "\t");
  26.         }
  27.         print ("\n");
  28.     }
  29.  
  30.     print (grid [0, 0].to_string () + "\n");
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement