Created
December 3, 2018 18:24
-
-
Save bradyt/f524c16509e693f2e5bd6b4b6af1c10b to your computer and use it in GitHub Desktop.
advent of code, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| with open('./input') as f: | |
| content = f.readlines() | |
| data = [] | |
| for line in content: | |
| m = re.match('#(\d+) @ (\d+),(\d+): (\d+)x(\d+)', line) | |
| next = [int(m.group(i)) for i in range(1, 6)] | |
| data.append(next) | |
| d = {} | |
| for next in data: | |
| elf, col, row, width, height = next | |
| for i in range(col, col+width): | |
| for j in range(row, row+height): | |
| elves = d.get((i, j), set()) | |
| elves.add(elf) | |
| d[(i, j)] = elves | |
| # part 1 | |
| result_1 = 0 | |
| for elves in d.values(): | |
| if len(elves) > 1: | |
| result_1 += 1 | |
| print(result_1) | |
| # part 2 | |
| result = 0 | |
| elves = set(next[0] for next in data) | |
| for cell in d.values(): | |
| if len(cell) > 1: | |
| for elf in cell: | |
| elves.discard(elf) | |
| print(elves.pop()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment