package tp2.exercises;

import java.util.List;

public class Exercise1 {
	private static int[][] matriz;
	
	public static int main(String[] args) {
		return exercise1(4);
	}
	
	public static int exercise1(int pisos) {
		matriz = new int[pisos][pisos];
		for (int i = 0; i < matriz.length; i++) {
			for (int j = 0; j < matriz.length; j++) {
				if (j == i){
					matriz[i][j] = 0;
				} else {
					matriz[i][j] = -2;
				}
			}
		}
		
		matriz[0][1] = -1;
		matriz[0][3] = -1;
		matriz[1][2] = -1;
		matriz[1][3] = -1;
		matriz[2][3] = -1;
		
//		for (Portal portal : portales) {
//			matriz[portal.getFrom()][portal.getTo()] = -1;
//		}
		
		return resolver();
		
	}
	private static int resolver() {
		for (int i = 0; i < matriz.length -1; i++) {
			if (matriz[i][matriz.length-1] == -1){
				matriz[i][matriz.length-1] = 1;
			}
		}
		
		int portales;
		for (int i = matriz.length -2; i >= 0; i--) {
			portales = 2;
			for (int j = matriz.length - 2; j > i; j--) {
				if (matriz[i][j] == -1 && matriz[i+1][j+1] > 0){
					matriz[i][j] = matriz[i+1][j+1] + 1;
				}
				portales++;
			}
		}
		
		int max = 0;
		for (int i = 0; i < matriz.length; i++) {
			max = Math.max(max, matriz[0][i]);
		}
		
		
		System.out.println(matriz.toString().toString());
		return max;
		
	}

}

@@ -99,16 +99,46 @@
 atriz;%0A%09
+private static int%5B%5D  mejores;
 %0A%09public
@@ -194,9 +194,9 @@
 se1(
-4
+6
 );%0A%09
@@ -275,16 +275,44 @@
 pisos%5D;%0A
+%09%09mejores = new int%5Bpisos%5D;%0A
 %09%09for (i
@@ -542,61 +542,230 @@
 riz%5B
-1%5D%5B2%5D = -1;%0A%09%09matriz%5B1%5D%5B3%5D = -1;%0A%09%09matriz%5B2%5D%5B3%5D = -1;
+0%5D%5B4%5D = -1;%0A%09%09matriz%5B0%5D%5B6%5D = -1;%0A%09%09matriz%5B1%5D%5B2%5D = -1;%0A%09%09matriz%5B1%5D%5B4%5D = -1;%0A%09%09matriz%5B1%5D%5B5%5D = -1;%0A%09%09matriz%5B2%5D%5B3%5D = -1;%0A%09%09matriz%5B2%5D%5B4%5D = -1;%0A%09%09matriz%5B2%5D%5B5%5D = -1;%0A%09%09matriz%5B3%5D%5B4%5D = -1;%0A%09%09matriz%5B4%5D%5B6%5D = -1;%0A%09%09matriz%5B5%5D%5B6%5D = -1;%0A
 %0A%09%09%0A
@@ -1054,32 +1054,69 @@
 %0A%09%09%09
-%7D%0A%09%09%7D
+%09mejores%5Bi%5D = 1;%0A%09%09%09%7D else %7B
 %0A%09%09
-%0A
 %09%09
-int portales;
+mejores%5Bi%5D = -2;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09
 %0A%09%09f
@@ -1164,25 +1164,8 @@
 ) %7B%0A
-%09%09%09portales = 2;%0A
 %09%09%09f
@@ -1244,27 +1244,22 @@
 && m
-atriz%5Bi+1%5D%5Bj+1
+ejores%5Bj
 %5D %3E 0
+ 
 )%7B%0A%09
@@ -1282,128 +1282,38 @@
  = m
-atriz%5Bi+1%5D%5Bj+1%5D + 1;%0A%09%09%09%09%7D%0A%09%09%09%09portales++;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09int max = 0;%0A%09%09for (int i = 0; i %3C matriz.length; i++) %7B%0A%09%09%09max
+ejores%5Bj%5D + 1;%0A%09%09%09%09%09mejores%5Bi%5D
  = M
@@ -1321,18 +1321,25 @@
 th.max(m
-ax
+ejores%5Bi%5D
 , matriz
@@ -1343,77 +1343,30 @@
 riz%5B
-0%5D%5Bi
+i%5D%5Bj
 %5D);%0A
+%09%09
 %09%09%7D%0A%09%09
-%0A%09
 %09
+%7D
 %0A%09%09
-System.out.println(matriz.toString().toString());
+%7D
 %0A%09%09r
@@ -1376,17 +1376,21 @@
 rn m
-ax;%0A%09
+ejores%5B0%5D;
 %09%0A%09%7D%0A
-%0A
 %7D%0A

Update Exercise1.java