Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.List;
- /**
- * @author /u/Philboyd_Studge on 12/7/2015.
- */
- public class Advent8 {
- public static void main(String[] args) {
- List<String> input = FileIO.getFileAsList("advent8.txt");
- int literals = input.stream()
- .mapToInt(x -> x.length())
- .sum();
- int memory = input.stream()
- .map(x -> x.replace("\\\\", "S"))
- .map(x -> x.replace("\\\"", "Q"))
- .map(x -> x.replaceAll("\"", ""))
- .map(x -> x.replaceAll("\\\\x[0-9a-f]{2}", "X"))
- .mapToInt(x -> x.length())
- .sum();
- System.out.println(literals - memory);
- // part 2
- int embiggen = input.stream()
- .map(x -> x.replaceAll("\\\\x[0-9a-f]{2}", "XXXXX"))
- .map(x -> x.replace("\\\"", "QQQQ"))
- .map(x -> x.replace("\\\\", "SSSS"))
- .mapToInt(x -> x.length() + 4)
- .sum();
- System.out.println(embiggen - literals);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment