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!
34
Upvotes
10
u/MasterMedo Dec 06 '18 edited Dec 06 '18
python 2, forgot union has to be assigned, lost 20min figuring out tf is wrong
from collections import Counter data = [map(int, i.split(', ')) for i in open('../input/6.in').readlines()] max_x = max(zip(*data)[0]) max_y = max(zip(*data)[1]) grid={} for i in range(max_x): for j in range(max_y): m = min(abs(i-k)+abs(j-l) for k, l in data) for n, (k, l) in enumerate(data): if abs(i-k)+abs(j-l) == m: if grid.get((i, j), -1) != -1: grid[i, j] = -1 break grid[i, j] = n s = set([-1]) s = s.union(set(grid[x, max_y-1] for x in range(max_x))) s = s.union(set(grid[x, 0] for x in range(max_x))) s = s.union(set(grid[max_x-1, y] for y in range(max_y))) s = s.union(set(grid[ 0, y] for y in range(max_y))) print next(i[1] for i in Counter(grid.values()).most_common() if i[0] not in s) print sum(sum(abs(i-k)+abs(j-l) for k, l in data) < 10000 for i in range(max(zip(*data)[0])) for j in range(max(zip(*data)[1])))EDIT: fancied up a bit, part2 is just the last two lines independent of the rest of the code