Created
December 25, 2015 10:09
-
-
Save paulhoadley/6e4954f4d84f8756b87a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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