Guest User

Untitled

a guest
Dec 8th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.util.List;
  2.  
  3. /**
  4.  * @author /u/Philboyd_Studge on 12/7/2015.
  5.  */
  6. public class Advent8 {
  7.  
  8.     public static void main(String[] args) {
  9.         List<String> input = FileIO.getFileAsList("advent8.txt");
  10.  
  11.         int literals = input.stream()
  12.                 .mapToInt(x -> x.length())
  13.                 .sum();
  14.  
  15.         int memory = input.stream()
  16.                 .map(x -> x.replace("\\\\", "S"))
  17.                 .map(x -> x.replace("\\\"", "Q"))
  18.                 .map(x -> x.replaceAll("\"", ""))
  19.                 .map(x -> x.replaceAll("\\\\x[0-9a-f]{2}", "X"))
  20.                 .mapToInt(x -> x.length())
  21.                 .sum();
  22.  
  23.         System.out.println(literals - memory);
  24.  
  25.         // part 2
  26.  
  27.         int embiggen = input.stream()
  28.                 .map(x -> x.replaceAll("\\\\x[0-9a-f]{2}", "XXXXX"))
  29.                 .map(x -> x.replace("\\\"", "QQQQ"))
  30.                 .map(x -> x.replace("\\\\", "SSSS"))
  31.                 .mapToInt(x -> x.length() + 4)
  32.                 .sum();
  33.  
  34.         System.out.println(embiggen - literals);
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment