package com.fishercoder.solutions;

/**
 * 38. Count and Say
 *
 * The count-and-say sequence is the sequence of integers beginning as follows:
 1, 11, 21, 1211, 111221, ...

 1 is read off as "one 1" or 11.
 11 is read off as "two 1s" or 21.
 21 is read off as "one 2, then one 1" or 1211.
 Given an integer n, generate the nth sequence.

 Note: The sequence of integers will be represented as a string.*/

public class _38 {
  public static class Solution1 {
    public String countAndSay(int n) {
      StringBuilder curr = new StringBuilder("1");
      StringBuilder prev;
      int count;
      char say;
      for (int i = 1; i < n; i++) {
        prev = curr;
        curr = new StringBuilder();
        count = 1;
        say = prev.charAt(0);

        for (int j = 1, len = prev.length(); j < len; j++) {
          if (prev.charAt(j) != say) {
            curr.append(count).append(say);
            count = 1;
            say = prev.charAt(j);
          } else {
            count++;
          }
        }
        curr.append(count).append(say);
      }
      return curr.toString();
    }
  }

}

@@ -33,380 +33,8 @@
 s;%0A%0A
-/**%0A * 38. Count and Say%0A *%0A * The count-and-say sequence is the sequence of integers beginning as follows:%0A 1, 11, 21, 1211, 111221, ...%0A%0A 1 is read off as %22one 1%22 or 11.%0A 11 is read off as %22two 1s%22 or 21.%0A 21 is read off as %22one 2, then one 1%22 or 1211.%0A Given an integer n, generate the nth sequence.%0A%0A Note: The sequence of integers will be represented as a string.*/%0A%0A
 publ
@@ -48,16 +48,18 @@
 s _38 %7B%0A
+  
   public
@@ -84,24 +84,28 @@
 tion1 %7B%0A    
+   
+ 
 public Strin
@@ -123,24 +123,30 @@
 ay(int n) %7B%0A
+      
       String
@@ -186,24 +186,30 @@
 %221%22);%0A      
+ 
+     
 StringBuilde
@@ -222,16 +222,22 @@
 ;%0A      
+    
+  
 int coun
@@ -245,16 +245,22 @@
 ;%0A      
+   
+   
 char say
@@ -263,24 +263,30 @@
  say;%0A      
+ 
+     
 for (int i =
@@ -299,24 +299,32 @@
 %3C n; i++) %7B%0A
+        
         prev
@@ -336,24 +336,32 @@
 rr;%0A        
+    
+    
 curr = new S
@@ -372,24 +372,32 @@
 gBuilder();%0A
+        
         coun
@@ -403,32 +403,40 @@
 nt = 1;%0A        
+      
+  
 say = prev.charA
@@ -442,16 +442,24 @@
 At(0);%0A%0A
+        
         
@@ -521,16 +521,26 @@
         
+       
+   
 if (prev
@@ -564,32 +564,44 @@
 ) %7B%0A            
+      
+      
 curr.append(coun
@@ -620,32 +620,44 @@
 y);%0A            
+   
+         
 count = 1;%0A     
@@ -655,32 +655,44 @@
  1;%0A            
+        
+    
 say = prev.charA
@@ -697,16 +697,26 @@
 rAt(j);%0A
+          
         
@@ -734,24 +734,36 @@
             
+    
+        
 count++;%0A   
@@ -761,34 +761,52 @@
 nt++;%0A          
+         
+ 
 %7D%0A
+        
         %7D%0A      
@@ -791,32 +791,40 @@
               %7D%0A
+        
         curr.app
@@ -849,26 +849,38 @@
 say);%0A      
+ 
-%7D%0A
+     %7D%0A      
       return
@@ -901,17 +901,23 @@
 ();%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%0A%7D%0A

refactor 38