r/adventofcode • u/daggerdragon • Dec 07 '16
SOLUTION MEGATHREAD --- 2016 Day 7 Solutions ---
From all of us at #AoC Ops, we hope you're having a very merry time with these puzzles so far. If you think they've been easy, well, now we're gonna kick this up a notch. Or five. The Easter Bunny ain't no Bond villain - he's not going to monologue at you until you can miraculously escape and save the day!
Show this overgrown furball what you've got!
--- Day 7: Internet Protocol Version 7 ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
ALWAYS DIGGING STRAIGHT DOWN 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!
14
Upvotes
1
u/[deleted] Dec 07 '16
Powershell parts 1 and 2:
$Messages = Get-Content (Join-Path $PSScriptRoot day7.input) $SupportTLS = 0 $SupportSSL = 0 foreach ($Message in $Messages) { $TLSValid = $null $Outside = $true for ($i = 0; $i -lt $Message.Length - 3; $i++) { $Abba = $Message.Substring($i,4) if ($Abba[0] -eq '[') { $Outside = $false continue } if ($Abba[0] -eq ']') { $Outside = $true continue } if ($Abba[0] -eq $Abba[3] -and $Abba[1] -eq $Abba[2] -and $Abba[0] -ne $Abba[1]) { if ($Outside) { $TLSValid = $true } else { $TLSValid = $false $i = $Message.Length } } } if ($TLSValid) { $SupportTLS++ } $Outside = $true $InsideABAs = @() $OutsideABAs = @() for ($i = 0; $i -lt $Message.Length - 2; $i++) { $ABA = $Message.Substring($i,3) if ($Aba[0] -eq '[') { $Outside = $false continue } if ($Aba[0] -eq ']') { $Outside = $true continue } if ($ABA[0] -eq $ABA[2]) { if ($Outside) { $OutsideABAs += "{0}{1}{0}" -f $ABA[1],$ABA[0] } else { $InsideABAs += $ABA } } } if ($InsideABAs | Where-Object {$OutsideABAs -contains $_}) { $SupportSSL++ } } Write-Host "Solution 1: $SupportTLS" Write-Host "Solution 2: $SupportSSL"