Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * @author /u/Philboyd_Studge on 12/9/2015.
- */
- public class Advent10 {
- public static List<Integer> toInt(String in) {
- return in.chars()
- .map(x -> x - '0')
- .boxed()
- .collect(Collectors.toList());
- }
- public static List<Integer> lookAndSay(List<Integer> in) {
- List<Integer> out = new ArrayList<>(in.size() * 2);
- int count = 1;
- for(int i=1; i< in.size();i++) {
- if (in.get(i).equals(in.get(i-1))) {
- count++;
- } else {
- out.add(count);
- out.add(in.get(i-1));
- count = 1;
- }
- }
- out.add(count);
- out.add(in.get(in.size()-1));
- return out;
- }
- public static void main(String[] args) {
- long time = System.currentTimeMillis();
- List<Integer> list = toInt("1113122113");
- for (int i = 0;i < 50; i++) {
- list = lookAndSay(list);
- }
- System.out.println("Length: " + list.size());
- System.out.println("Time: "+(System.currentTimeMillis() - time) + "ms");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment