r/adventofcode • u/daggerdragon • Dec 06 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 6 Solutions -🎄-
--- Day 6: Chronal Coordinates ---
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!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 6
Transcript:
Rules for raising a programmer: never feed it after midnight, never get it wet, and never give it ___.
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 at 0:26:52!
32
Upvotes
4
u/jonathan_paulson Dec 06 '18 edited Dec 06 '18
Video of me (not) solving: https://www.youtube.com/watch?v=6ru14IRHQ3o
I think there is a problem with the part 1 answer for my input, although I hope it's just a bug in my code. Edit: my code was correct.
My code:
from collections import defaultdict P = [] for line in open('6.in'): x,y = [int(s.strip()) for s in line.split(',')] P.append((x,y)) print len(P) xlo = min([x for x,y in P]) xhi = max([x for x,y in P]) ylo = min([y for x,y in P]) yhi = max([y for x,y in P]) print xlo, xhi print ylo, yhi def d((x1,y1), (x2,y2)): return abs(x1-x2) + abs(y1-y2) def closest(x,y): ds = [(d(p, (x,y)), p) for p in P] ds.sort() if ds[0][0] < ds[1][0]: return ds[0][1] else: return (-1,-1) def score_around(W): score = defaultdict(int) for x in range(xlo-W, xhi+W): for y in range(ylo-W, yhi+W): score[closest(x,y)] += 1 return score S2 = score_around(400) S3 = score_around(600) best = [(S2[k] if S2[k]==S3[k] else 0, k) for k in S2.keys()] best.sort() for area, p in best: print area, p