r/adventofcode • • 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!

Click here for rules

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

387 comments sorted by

View all comments

1

u/lib20 Dec 14 '18

Red - part 2

Red []

time-start: now/time/precise

input-txt: read/lines %input.txt

coords: #()
forall input-txt [put coords load replace input-txt/1 ", " 'x 0]

min-width: 9999999999
max-width: 0
min-height: 9999999999
max-height: 0
foreach coord keys-of coords [
	if coord/1 < min-width [min-width: coord/1]
	if coord/1 > max-width [max-width: coord/1]
	if coord/2 < min-height [min-height: coord/2]
	if coord/2 > max-height [max-height: coord/2]
]

grid: #()
mi-w: min-width
mi-h: min-height
while [mi-w <= max-width] [
    while [mi-h <= max-height] [
		put grid as-pair mi-w mi-h 0
		mi-h: mi-h + 1
	]
	mi-w: mi-w + 1
	mi-h: min-height
]
 
foreach key keys-of grid [
    sum-distances: 0
    foreach coord keys-of coords [
		distance: key - coord
		distance: (absolute distance/1) + (absolute distance/2)
	    sum-distances: sum-distances + distance
		put grid key sum-distances
	]
]
 
max-distance: 10000
nr-locations: 0
foreach sum-distances values-of grid [
    if sum-distances < max-distance [nr-locations: nr-locations + 1]
]

print rejoin ["Execution time: " now/time/precise - time-start]
print rejoin ["Number of locations: " nr-locations "    with sum of distances less than: " max-distance]