From: Neil Smith Date: Tue, 20 Dec 2016 09:45:27 +0000 (+0000) Subject: Done day 20 X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-16.git;a=commitdiff_plain;h=3dfbda126957813743b3f7bf2a2b240e7e83979a Done day 20 --- diff --git a/advent20.hs b/advent20.hs index aab974a..8935f86 100644 --- a/advent20.hs +++ b/advent20.hs @@ -19,7 +19,7 @@ main = do text <- readFile "advent20.txt" let intervals = successfulParse $ parseIfile text part1 intervals - -- part2 + part2 intervals part1 :: [Interval] -> IO () part1 intervals = print $ (+1) $ high $ head $ foldl' (mergeAdjacent) [] $ foldl' (merge) [] intervals @@ -28,8 +28,8 @@ part2 :: [Interval] -> IO () part2 intervals = do let ints = foldl' (mergeAdjacent) [] $ foldl' (merge) [] intervals let gapCount = gaps ints - let lowGap = max [0, ((low $ head ints) -1)] - let highGap = 4294967295 - (min [4294967295, ((high $ last ints) + 1)]) + let lowGap = low $ head ints + let highGap = 4294967295 - (high $ last ints) print (lowGap + gapCount + highGap) -- 4294967295 diff --git a/day20.html b/day20.html new file mode 100644 index 0000000..f798abd --- /dev/null +++ b/day20.html @@ -0,0 +1,140 @@ + + + + +Day 20 - Advent of Code 2016 + + + + + + +

Advent of Code

Neil Smith (AoC++) 40*

   sub y{2016}

+ + + +
+

--- Day 20: Firewall Rules ---

You'd like to set up a small hidden computer here so you can use it to get back into the network later. However, the corporate firewall only allows communication with certain external IP addresses.

+

You've retrieved the list of blocked IPs from the firewall, but the list seems to be messy and poorly maintained, and it's not clear which IPs are allowed. Also, rather than being written in dot-decimal notation, they are written as plain 32-bit integers, which can have any value from 0 through 4294967295, inclusive.

+

For example, suppose only the values 0 through 9 were valid, and that you retrieved the following blacklist:

+
5-8
+0-2
+4-7
+
+

The blacklist specifies ranges of IPs (inclusive of both the start and end value) that are not allowed. Then, the only IPs that this firewall allows are 3 and 9, since those are the only numbers not in any range.

+

Given the list of blocked IPs you retrieved from the firewall (your puzzle input), what is the lowest-valued IP that is not blocked?

+
+

Your puzzle answer was 31053880.

--- Part Two ---

How many IPs are allowed by the blacklist?

+
+

Your puzzle answer was 117.

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, you should return to your advent calendar and try another puzzle.

+

If you still want to see it, you can get your puzzle input.

+

You can also this puzzle.

+
+ + + + + + \ No newline at end of file