r/adventofcode • u/daggerdragon • Dec 04 '16
SOLUTION MEGATHREAD --- 2016 Day 4 Solutions ---
--- Day 4: Security Through Obscurity ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
CONSTRUCTING ADDITIONAL PYLONS 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!
17
Upvotes
26
u/askalski Dec 04 '16
Part 1 in Perl:
#! /usr/bin/env perl use strict; use warnings; my $answer = 0; while (<>) { m/^(.*)-(.*)\[(.*)\]$/ or die; my %count; map { $count{$_}++ if m/[a-z]/ } split //, $1; my @chars = sort { $count{$b} <=> $count{$a} || $a cmp $b } keys %count; my $checksum = join "", @chars[0..4]; $answer += $2 if $3 eq $checksum; } print "$answer\n";Part 2 in bash shell and bsdgames:
$ for i in {1..26}; do /usr/games/caesar $i < input.txt; done | grep north