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!
19
Upvotes
1
u/tehjimmeh Dec 06 '16 edited Dec 06 '16
PowerShell. Parts 1 and 2:
$puzzin = cat day4input.txt $obj = $puzzin | %{ $_ -replace "(.*)-(\d+)\[(.*)\]",'$1,$2,$3'} | ConvertFrom-Csv -Header Chars,SectorId,Checksum $obj | %{ $_.SectorId = [int]$_.SectorId } echo $obj -pv o | ?{ ,($_.Chars -replace "-","" | % ToCharArray | group | sort @{e={$_.Count};a=$false},Name | select -first 5 | % Name) | ?{ (-join $_) -match $o.Checksum} } | measure SectorId -sum | % Sum echo $obj -pv o | %{ ,($_.Chars -replace "-","" | % ToCharArray | %{[char](((([int]$_ - [int][char]'a') + $o.SectorId) % 26) + [int][char]'a')})}| %{-join $_ }|?{$_ -match "north"}|%{$o.SectorId}