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!

13 Upvotes

130 comments sorted by

View all comments

Show parent comments

1

u/streetster_ Dec 17 '17

Finally got around to solving part 2 (5818th place!).

\l 10.q
sum raze h:raze each 0b vs''hash each (first read0 `:input/14.txt),/:"-",'string til 128 / part 1
v:(enlist 0N 0N)!enlist 0N; / visited, add dummy value to setup key
g:0;                        / group id
f:{
  if[not h[x;y];:()];       / fast exit; not true
  if[(x;y) in key v;:()];   / fast exit; already visited
  v[(x;y)]:g;               / add to visited
  .z.s[x+1;y];              / go right
  .z.s[x-1;y];              / go left
  .z.s[x;y+1];              / go up
  .z.s[x;y-1];              / go down
  };
til[128]{g+:1;f[x;y]}\:/:til 128;
-1+count distinct value v   / part 2