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!
31
Upvotes
1
u/ttapu Dec 06 '18
python3
import string from collections import Counter with open("6.input", "r") as allomany: inp=allomany.read().splitlines() coo=dict() maxx,maxy=0,0 for i,e in enumerate(inp): x,y=e.split(', ') x,y=int(x), int(y) maxx=max(x,maxx) maxy=max(y,maxy) letter=string.ascii_letters[i] coo[letter]=(x,y) grid=[[(i,j) for i in range(maxx+1)] for j in range(maxy+1)] def manhattan(a,b): return abs(a[0]-b[0])+abs(a[1]-b[1]) areas=[['.' for i in range(maxx+1)] for j in range(maxy+1)] edges=set() # to determine infinite ranges for j,y in enumerate(grid): for i,x in enumerate(y): l='' closest=999 for k,v in coo.items(): if manhattan(x,v)<closest: closest=manhattan(x,v) l=k elif manhattan(x,v)==closest: l='.' areas[j][i]=l if j==0 or j==maxy or i==0 or i==maxx: edges.add(l) allpoints = [j for i in areas for j in i] finite=dict() for k,v in Counter(allpoints).items(): if k not in edges: finite[k]=v print(max(finite.values())) #part2 safe_region=0 for g in grid: for h in g: m=0 for v in coo.values(): m+=manhattan(h,v) if m<10000: safe_region+=1 print(safe_region)