Skip to content

Instantly share code, notes, and snippets.

@roccodev
Created December 9, 2017 08:09
Show Gist options
  • Select an option

  • Save roccodev/f57f2b365cbbedcf3edb7b108e2ccc99 to your computer and use it in GitHub Desktop.

Select an option

Save roccodev/f57f2b365cbbedcf3edb7b108e2ccc99 to your computer and use it in GitHub Desktop.
AdventOfCode2017/Day9
public static void main(String[] args) throws IOException {
List<String> bloccs = Files.readAllLines(Paths.get(new File("res/day9").getPath())).stream()
.collect(Collectors.toList());
String x = bloccs.get(0).trim();
boolean garbage = false;
int score = 0;
int depth = 0;
int count = 0;
for (int i = 0; i < x.length(); i++) {
char c = x.charAt(i);
if (garbage && c == '!')
i++;
else if (garbage && c != '>')
count++;
else if (c == '<')
garbage = true;
else if (c == '>')
garbage = false;
else if (c == '{')
score += ++depth;
else if (c == '}')
depth--;
}
System.out.println("Score: " + score);
System.out.println("P2: " + count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment