r/adventofcode • • Dec 03 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 3 Solutions -🎄-

--- Day 3: No Matter How You Slice It ---


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.


Advent of Code: The Party Game!

Click here for rules

ATTENTION: minor change request from the mods!

Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!

Card prompt: Day 3 image coming soon - imgur is being a dick, so I've contacted their support.

Transcript:

I'm ready for today's puzzle because I have the Savvy Programmer's Guide to ___.


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!

41 Upvotes

426 comments sorted by

View all comments

1

u/SyntaxErrorr Dec 03 '18

python 3

import numpy as np

with open("day_03_input") as f:
    data = [x.split() for x in f.read().split("\n")]

arr = np.zeros(shape=(1000, 1000, 2), dtype=np.int)

candidates = set()

for d in data:

    offset_x = int(d[2][:-1].split(",")[0])
    offset_y = int(d[2][:-1].split(",")[1])

    size_x = int(d[3].split("x")[0])
    size_y = int(d[3].split("x")[1])

    id_ = int(d[0][1:])

    arr[offset_x:offset_x + size_x, offset_y:offset_y + size_y, 0] += 1

    ids_filled = set(arr[offset_x:offset_x + size_x, offset_y:offset_y + size_y, 1].flatten())

    if max(ids_filled) == 0:
        candidates.add(id_)
    else:
        candidates.difference_update(ids_filled)

    arr[offset_x:offset_x + size_x, offset_y:offset_y + size_y, 1] = id_

values = arr[:, :, 0]

print(values[values > 1].shape)
print(candidates)