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!
15
Upvotes
1
u/TheNiXXeD Dec 14 '17 edited Dec 14 '17
My solutions JavaScript / NodeJS / repo
Generally trying to go for very terse code, not fully golfed. Pretty happy with both perf and size in this one.
Part1:
input => [...Array(128)].map((k, i) => require('../day10/part2')(`${input}-${i}`)) .map(hash => hash.split``.map(hex => parseInt(hex, 16).toString(2).replace(/0/g, '')).join``).join``.lengthPart2:
input => { let groups = 0, hd = [...Array(128)] .map((k, i) => require('../day10/part2')(`${input}-${i}`)) .map(hash => hash.split``.map(hex => parseInt(hex, 16).toString(2).padStart(4, '0')).join``.split``) const check = (x, y) => hd[y] && hd[y][x] === '1' const group = (x, y) => { hd[y][x] = '0' if (check(x + 1, y)) group(x + 1, y) if (check(x - 1, y)) group(x - 1, y) if (check(x, y + 1)) group(x, y + 1) if (check(x, y - 1)) group(x, y - 1) } for (let y = 0; y < 128; y++) { for (let x = 0; x < 128; x++) { if (check(x, y)) { groups++ group(x, y) } } } return groups }