Solved last night, refactored this morning! Actually pretty proud of this. Python solution:
import re with open('input.txt', 'r') as f: data = [] for line in f: nums = [int(n) for n in re.findall(r'\d+', line)] data.append({'id': nums[0], 'coordinates': [nums[1], nums[2]], 'dimensions': [nums[3], nums[4]]}) def get_coordinates(coordinates, dimensions): for x in range(dimensions[0]): for y in range(dimensions[1]): yield str(x + coordinates[0]) + "," + str(y + coordinates[1]) def get_overlaps(data): overlaps = set() filled = set() for line in data: for coord in get_coordinates(line['coordinates'], line['dimensions']): if coord in filled: overlaps.add(coord) else: filled.add(coord) return overlaps def no_overlaps(coordinates, dimensions, overlaps): for coord in get_coordinates(coordinates, dimensions): if coord in overlaps: return False return True def find_no_overlaps(data, overlaps): for line in data: if no_overlaps(line['coordinates'], line['dimensions'], overlaps): return line['id'] overlaps = get_overlaps(data) # Q1 print(len(overlaps)) # Q2 print(find_no_overlaps(data, overlaps))
I love how clean this solution is!
Thank you so much -- that means a lot (I've been super sad this morning because somebody was mean about my solution on Twitter).
๐People can be the worst sometimes. Sorry you had to deal with that.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Solved last night, refactored this morning! Actually pretty proud of this. Python solution:
I love how clean this solution is!
Thank you so much -- that means a lot (I've been super sad this morning because somebody was mean about my solution on Twitter).
๐People can be the worst sometimes. Sorry you had to deal with that.