Created
December 20, 2016 07:05
-
-
Save anonymous/b85db53f71662355166e7b71adfd3df9 to your computer and use it in GitHub Desktop.
Advent of Code 2016 Day 20 /u/Philboyd_Studge
This file contains 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
import java.util.*; | |
/** | |
* @author /u/Philboyd_Studge on 12/19/2016. | |
*/ | |
public class Advent2016_20 { | |
public static void main(String[] args) { | |
List<String[]> input = FileIO.getFileLinesSplit("advent14.txt", "-"); | |
TreeMap<Long, Long> blocked = new TreeMap<>(); | |
for (String[] each : input) { | |
blocked.put(Long.parseLong(each[0]), Long.parseLong(each[1])); | |
} | |
Iterator<Long> i = blocked.navigableKeySet().iterator(); | |
Long first = i.next(); | |
Long last = 0L; | |
Long count = 0L; | |
while (i.hasNext()) { | |
Long current = i.next(); | |
if ((blocked.get(first) + 1) > last) last = blocked.get(first) + 1; | |
if (current > last) { | |
System.out.println("unblocked " + last + " : current " + current); | |
count += current - last; | |
} | |
first = current; | |
} | |
System.out.println(count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment