package leetcode;

/**
 * https://leetcode.com/problems/k-th-symbol-in-grammar/
 */
public class Problem779 {
    public int kthGrammar(int N, int K) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem779 prob = new Problem779();
        System.out.println(prob.kthGrammar(1, 1)); // 0
        System.out.println(prob.kthGrammar(2, 1)); // 0
        System.out.println(prob.kthGrammar(2, 2)); // 1
        System.out.println(prob.kthGrammar(4, 5)); // 1
    }
}

@@ -157,32 +157,653 @@
     
-// TODO%0A        return 0
+int%5B%5D cols = new int%5BN%5D;%0A        cols%5BN - 1%5D = K;%0A        for (int row = N - 2; row %3E= 0; row--) %7B%0A            cols%5Brow%5D = (int) Math.ceil(cols%5Brow + 1%5D / 2.0);%0A        %7D%0A        String s = %220%22;%0A        for (int row = 0; row %3C N; row++) %7B%0A            String tmp = %22%22;%0A            for (int i = 0; i %3C s.length(); i++) %7B%0A                if (s.charAt(i) == '0') %7B%0A                    tmp += %2201%22;%0A                %7D else %7B%0A                    tmp += %2210%22;%0A                %7D%0A                if (tmp.length() %3E= cols%5Brow%5D) %7B%0A                    break;%0A                %7D%0A            %7D%0A            s = tmp;%0A        %7D%0A        return s.charAt(K - 1) - '0'
 ;%0A  
@@ -848,24 +848,44 @@
 g%5B%5D args) %7B%0A
+        // 01101001%0A
         Prob
@@ -916,16 +916,18 @@
 m779();%0A
+//
         
@@ -966,32 +966,34 @@
 ar(1, 1)); // 0%0A
+//
         System.o
@@ -1032,16 +1032,18 @@
 ); // 0%0A
+//
         
@@ -1086,24 +1086,26 @@
 , 2)); // 1%0A
+//
         Syst
@@ -1148,16 +1148,81 @@
 ); // 1%0A
+        System.out.println(prob.kthGrammar(30, 434991989)); // 1%0A
     %7D%0A%7D%0A

Update problem 779