Skip to content

Instantly share code, notes, and snippets.

@paulhoadley
Created December 25, 2015 10:09
Show Gist options
  • Save paulhoadley/6e4954f4d84f8756b87a to your computer and use it in GitHub Desktop.
Save paulhoadley/6e4954f4d84f8756b87a to your computer and use it in GitHub Desktop.
package net.logicsquad.advent;
public class Day10 {
public static void main(String[] args) {
String input = "1321131112";
for (int i = 0; i < 40; i++) {
input = lookAndSay(input);
}
System.out.println("Day10.main: input.length() = " + input.length());
return;
}
public static String lookAndSay(String input) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
int count = 1;
while (i + count < input.length() && input.charAt(i + count) == c) {
count++;
}
result.append(count);
result.append(c);
i += count - 1;
}
return result.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment