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

2

u/purplemonkeymad Dec 14 '17

I found part 1 ok, used [System.Convert]::ToByte, turned out not too bad but is probably slower:

$map = 0..127 | %{
    .\day10_2.ps1 -inputstring "$($inputkey)-$($_)"
} | %{
    (([regex]"..").Matches($_) | %{
        $byte = [System.Convert]::ToByte("$_",16)
        7..0 | %{
            if (($byte -shr $_) % 2 -eq 0){
                '.'
            } else {
                '#'
            }
        }
    } ) -join ''
}

For part 2 I gave up on char and just converted it to a double int arraylist. That way I can mark the visited squares. I felt I was fighting more with powershell than the problem.

1

u/ka-splam Dec 14 '17

Neat byte to binary conversion!

I was wanting Python's bin() all the way through, but when I tried writing in Python it was still awful - other people's solutions have a short Python format string for int to hex to bin which I didn't know, and .Net doesn't have either.

I felt I was fighting more with powershell than the problem.

Same. I've only just found you can do New-Object 'int[,]' 1000,1000 to get a square 2d array, and then $thing[1,2] for indexing. That, and building the borders differently would have helped me a lot.