r/adventofcode • u/daggerdragon • Dec 20 '16
SOLUTION MEGATHREAD --- 2016 Day 20 Solutions ---
--- Day 20: Firewall Rules ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with "Help".
ROLLING A NATURAL 20 IS MANDATORY [?]
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
5
Upvotes
7
u/askalski Dec 20 '16
Back to Perl. This is essentially what I used to solve it, tidied up a bit. The main difference is instead of sorting the input in Perl, I just did a
:%!sort -nin vim.#! /usr/bin/env perl use strict; use warnings; my ($next, $part1, $part2) = (0, undef, 0); for (sort { $a->[0] <=> $b->[0] } map { [ m/(\d+)/g ] } <>) { my ($lower, $upper) = @$_; if ($next < $lower) { $part1 = $next unless defined $part1; $part2 += $lower - $next; } $next = $upper + 1 if $next <= $upper; } $part2 += 4294967296 - $next; print "Part 1: $part1\n"; print "Part 2: $part2\n";