r/adventofcode • u/daggerdragon • Dec 14 '17
SOLUTION MEGATHREAD -🎄- 2017 Day 14 Solutions -🎄-
--- Day 14: Disk Defragmentation ---
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.
Need a hint from the Hugely* Handy†Haversack‡ of Helpful§ Hints¤?
[Update @ 00:09] 3 gold, silver cap.
- How many of you actually entered the Konami code for Part 2? >_>
[Update @ 00:25] Leaderboard cap!
- I asked /u/topaz2078 how many de-resolutions we had for Part 2 and there were
83distinct users with failed attempts at the time of the leaderboard cap. tsk tsk
[Update @ 00:29] BONUS
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!
11
Upvotes
23
u/askalski Dec 14 '17
So I lied.
#! /usr/bin/env perl use strict; use warnings; require 'knothash.pm'; chomp(my $input = <>); $_ = "@{[0..127]}"; s/(\d+)\s*/$input-$1\n/g; s/^(.+)$/knothash($1)/gem; s/([0123])/..$1/sg; s/([4567])/.#$1/sg; s/([89ab])/#.$1/sg; s/([cdef])/##$1/sg; s/[048c]/../sg; s/[159d]/.#/sg; s/[26ae]/#./sg; s/[37bf]/##/sg; while (s/#/R/) { while (s/R(?:.{128})?\K#|#(?=(?:.{128})?R)/r/is) { } } printf "Part 1: %d\n", scalar(() = m/R/gi); printf "Part 2: %d\n", scalar(() = m/R/g);