Skip to content

Instantly share code, notes, and snippets.

Created December 20, 2016 07:05
Show Gist options
  • Save anonymous/b85db53f71662355166e7b71adfd3df9 to your computer and use it in GitHub Desktop.
Save anonymous/b85db53f71662355166e7b71adfd3df9 to your computer and use it in GitHub Desktop.
Advent of Code 2016 Day 20 /u/Philboyd_Studge
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