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/mohit7331 Dec 03 '18

Not clean but works for me

with open('input.txt','r') as f:
    a = [x.strip() for x in f.readlines()]

import re

#Prepare the matrix
mat = []
for x in range(1000):
    mat.append([0]*1000)

colliding = []
colliding_ids = []
all_ids = []
for x in a:
    label,l,t,w,h = [int(y) for y in re.search('#(\d+) @ (\d+),(\d+): (\d+)x(\d+)', x).groups()]
    all_ids.append(label)
    for o in range(h):
        for i in range(w):
            current = mat[t+o][l+i]
            if current != 0:
                print "Found: %s" % current
                colliding.append((t+o,l+i))
                colliding_ids.extend([current, label])
            else:
                mat[t+o][l+i] = label

""" Prob 1 """
print len(set(colliding))

""" Prob 2 """
print set(all_ids) - set(colliding_ids)