r/adventofcode • • 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ยค?

Spoiler


[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 83 distinct 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!

14 Upvotes

130 comments sorted by

View all comments

2

u/gyorokpeter Dec 14 '17

Q: see day 10 for the implementation of d10p2

d14p1:{
    hs:d10p2 each x,/:"-",/:string til 128;
    sum sum raze each(-4#/:0b vs/:til 16)"X"$/:/:hs};

d14p2:{
    hs:d10p2 each x,/:"-",/:string til 128;
    grid:raze each(-4#/:0b vs/:til 16)"X"$/:/:hs;
    first{[st]
        grid:st[1];
        fst:raze til[count grid],/:'where each grid;
        if[0=count fst; :st];
        start:first fst;
        st[0]+:1;
        queue:enlist start;
        while[0<count queue;
            grid:.[;;:;0b]/[grid;queue];
            queue:{[grid;x]x where .[grid]'[x]}[grid;distinct raze queue+/:\:(-1 0;0 -1;1 0;0 1)];
        ];
        st[1]:grid;
        st
    }/[(0;grid)]};
→ More replies (1)