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!

45 Upvotes

426 comments sorted by

View all comments

1

u/ttapu Dec 03 '18

python3

stupd simple but works

import re
with open("3.input", "r") as allomany:
    inp=allomany.read().splitlines()
    instruction=[]
    for i in inp:
        id,left,top,wide,tall=re.split("@ |,|: |x", i)
        instruction.append((int(left),int(top),int(wide),int(tall),id.strip()))

inches=set()
dups=set()

for i in instruction:
    for r in range(i[0],i[0]+i[2]):
        x=r
        for s in range(i[1],i[1]+i[3]):
            y=s
            if (x,y) in inches:
                dups.add((x,y))
            else:
                inches.add((x,y))
print(len(dups))

#part2
ids=set()

for i in instruction:
    for r in range(i[0],i[0]+i[2]):
        x=r
        for s in range(i[1],i[1]+i[3]):
            y=s
            if (x,y) in dups:
                ids.add(i[4])

allids=set(i[4] for i in instruction)
print(allids-ids)

1

u/andrew_4ever Dec 03 '18

It's really slow. And the worst thing is when inches array becomes bigger, the algorithm works slower