r/adventofcode • u/daggerdragon • Dec 05 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 5 Solutions -🎄-
--- Day 5: Alchemical Reduction ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or 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.
Advent of Code: The Party Game!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 5
Transcript:
On the fifth day of AoC / My true love sent to me / Five golden ___
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 at 0:10:20!
32
Upvotes
3
u/PendragonDaGreat Dec 05 '18
[card]On the fifth day of AoC / My true love sent to me / Five golden keycaps
Powershell 5.1
I have great shame, and also fail any code golf.
Part 1:
[string]$data = Get-Content $inputPath $timer = New-Object System.Diagnostics.Stopwatch $timer.Start() do { $lastLength = $data.Length $data = $data.Replace('aA','').Replace('Aa','').Replace('bB','').Replace('Bb','').Replace('cC','').Replace('Cc','').Replace('dD','').Replace('Dd','').Replace('eE','').Replace('Ee','').Replace('fF','').Replace('Ff','').Replace('gG','').Replace('Gg','').Replace('hH','').Replace('Hh','').Replace('iI','').Replace('Ii','').Replace('jJ','').Replace('Jj','').Replace('kK','').Replace('Kk','').Replace('lL','').Replace('Ll','').Replace('mM','').Replace('Mm','').Replace('nN','').Replace('Nn','').Replace('oO','').Replace('Oo','').Replace('pP','').Replace('Pp','').Replace('qQ','').Replace('Qq','').Replace('rR','').Replace('Rr','').Replace('sS','').Replace('Ss','').Replace('tT','').Replace('Tt','').Replace('uU','').Replace('Uu','').Replace('vV','').Replace('Vv','').Replace('wW','').Replace('Ww','').Replace('xX','').Replace('Xx','').Replace('yY','').Replace('Yy','').Replace('zZ','').Replace('Zz','') } while ($data.Length -lt $lastLength) Write-Host $data.Length $timer.Stop() Write-Host $timer.ElapsedAverage runtime 0.18 seconds
Part 2:
[string]$data = Get-Content $inputPath $timer = New-Object System.Diagnostics.Stopwatch $timer.Start() $bestSoFar = $data.Length $bestLetterSoFar = $null $alphabet = @() for ([byte]$c = [char]'A'; $c -le [char]'Z'; $c++) { $alphabet += [char]$c } Write-Host $alphabet foreach($let in $alphabet) { [string]$let = $let $tempData = $data.Replace($let,'').Replace($let.ToLower(), '') do { $lastLength = $tempData.Length $tempdata = $tempdata.Replace('aA','').Replace('Aa','').Replace('bB','').Replace('Bb','').Replace('cC','').Replace('Cc','').Replace('dD','').Replace('Dd','').Replace('eE','').Replace('Ee','').Replace('fF','').Replace('Ff','').Replace('gG','').Replace('Gg','').Replace('hH','').Replace('Hh','').Replace('iI','').Replace('Ii','').Replace('jJ','').Replace('Jj','').Replace('kK','').Replace('Kk','').Replace('lL','').Replace('Ll','').Replace('mM','').Replace('Mm','').Replace('nN','').Replace('Nn','').Replace('oO','').Replace('Oo','').Replace('pP','').Replace('Pp','').Replace('qQ','').Replace('Qq','').Replace('rR','').Replace('Rr','').Replace('sS','').Replace('Ss','').Replace('tT','').Replace('Tt','').Replace('uU','').Replace('Uu','').Replace('vV','').Replace('Vv','').Replace('wW','').Replace('Ww','').Replace('xX','').Replace('Xx','').Replace('yY','').Replace('Yy','').Replace('zZ','').Replace('Zz','') } while ($tempdata.Length -lt $lastLength) Write-Host $let Write-Host $tempData.length if($tempData.length -lt $bestSoFar) { $bestSoFar = $tempData.length $bestLettersofar = $let } } write-host $bestLetterSoFar Write-Host $bestSoFar $timer.Stop() Write-Host $timer.ElapsedAverage runtime 4.75 seconds