package pl.xxlo;

public class Zadanie128 {
	
	int[] tab;
	final int size;
	
	public static void main(String[] args) {
		Zadanie128 z = new Zadanie128(10);
		z.test();
		z.drawBrutal();
		z.drawAdding();
	}
	
	public Zadanie128(int s) {
		size = s;
		tab = new int[size + 5];
	}
	
	public void drawBrutal() {
		for(int i = 0; i < size; i++) {
			for(int j = 0; j <= i; j++ ) {
				tab[j] = combine(i, j); 
			}
			drawTab(i);
		}
	}
	//not work
	public void drawAdding() {
		int next = 0;
		for(int i = 0; i < size; i++) {
			for(int j = 0; j <= i; j++ ) {
				if(j == 0 || j == i) {
					next = tab[j];
					tab[j] = 1;
				}
				else {
					tab[j] = next + tab[j];
				}
//				
			}
			drawTab(i);
		}
		
	}
	
	private void drawTab(int s) {
		for(int i = 0; i <= s; i++) {
			System.out.print(tab[i] + " ");
		}
		System.out.println();
	}
	
	private int factorial(int n) {
		int s = 1; 
		if(n <= 0) return 1;
		while( n >  1) {
			s *= n;
			n--;
		}
		return s;
	}
	
	private int combine(int n, int k) {
		return factorial(n)/ (factorial(n - k)*factorial(k));
	}
	
	public void test() {
		assert factorial(5) == 120;
		assert factorial(1) == 1;
		assert factorial(0) == 1;
		System.out.println("Combine 1, 1 = " + combine(1, 1));
	}

}

@@ -149,16 +149,18 @@
 28(10);%0A
+//
 %09%09z.test
@@ -474,20 +474,20 @@
 %7B%0A%09%09int 
-next
+prev
  = 0;%0A%09%09
@@ -584,20 +584,20 @@
  %7B%0A%09%09%09%09%09
-next
+prev
  = tab%5Bj
@@ -649,23 +649,43 @@
 %5Bj%5D 
++
 = 
-next + tab%5Bj%5D
+prev ;%0A%09%09%09%09%09prev = tab%5Bj%5D - prev
 ;%0A%09%09
@@ -782,50 +782,246 @@
  i %3C
-= s; i++) %7B%0A%09%09%09System.out.print(tab%5Bi%5D + %22
+ (10 - s) ; i++) System.out.print(%22  %22);%0A%09%09for(int i = 0; i %3C= s; i++) %7B%0A%09%09%09if(tab%5Bi%5D %25 100 %3E 0) System.out.print(tab%5Bi%5D + %22 %22);%0A%09%09%09else if(tab%5Bi%5D %25 10 %3E 0) System.out.print(%22 %22 + tab%5Bi%5D + %22 %22);%0A%09%09%09else System.out.print(%22 %22 + tab%5Bi%5D + %22  
  %22);
@@ -1272,32 +1272,34 @@
 orial(k));%0A%09%7D%0A%09%0A
+//
 %09public void tes
@@ -1304,16 +1304,18 @@
 est() %7B%0A
+//
 %09%09assert
@@ -1336,16 +1336,18 @@
 == 120;%0A
+//
 %09%09assert
@@ -1366,16 +1366,18 @@
 ) == 1;%0A
+//
 %09%09assert
@@ -1396,16 +1396,18 @@
 ) == 1;%0A
+//
 %09%09System
@@ -1455,14 +1455,16 @@
 1, 1));%0A
+//
 %09%7D%0A%0A%7D%0A

fix zad 128