Created
December 9, 2017 08:09
-
-
Save roccodev/f57f2b365cbbedcf3edb7b108e2ccc99 to your computer and use it in GitHub Desktop.
AdventOfCode2017/Day9
This file contains hidden or 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
| 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