fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. class Ideone
  5. {
  6. public static void main(String[] args)
  7. {
  8. String s = "0";
  9. for (int i = 0; i < 50; i++)
  10. {
  11. System.out.println(s);
  12. s = next(s);
  13. }
  14. }
  15.  
  16. static Pattern pattern = Pattern.compile("(.)\\1*");
  17. static String next(String s)
  18. {
  19. StringBuilder result = new StringBuilder();
  20.  
  21. Matcher m = pattern.matcher(s);
  22. while (m.find())
  23. {
  24. int length = m.group().length();
  25. if (length < 3) result.append(length);
  26. result.append(m.group(1));
  27. }
  28.  
  29. return result.toString();
  30. }
  31. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
0
10
1110
110
2110
122110
11222110
2122110
1211222110
11122122110
12211222110
11222122110
21211222110
1211122122110
111212211222110
11211222122110
211221211222110
12212211122122110
1122112212211222110
2122212211222122110
12112112221211222110
1112211221211122122110
1222122111212211222110
112112211211222122110
21122122211221211222110
122122112212211122122110
112211222122112212211222110
21222121122212211222122110
121121112212112221211222110
11122112122111221211122122110
12221121122122111212211222110
11221122122112211211222122110
2122212211222122211221211222110
121121122212112212211122122110
1112211221211122122112212211222110
122212211121221122212211222122110
11211221121122212112221211222110
211221222112212111221211122122110
12212211221221112122111212211222110
1122112221221122112112211211222122110
21222121122212221122122211221211222110
1211211122121122122112212211122122110
111221121221112212211222122112212211222110
1222112112212211222121122212211222122110
1122112212211222121112212112221211222110
2122212211222121112122111221211122122110
12112112221211121121122122111212211222110
11122112212111211221122122112211211222122110
122212211121122122212211222122211221211222110
112112211221221121122212112212211122122110