first commit
This commit is contained in:
1311
03/input.txt
Normal file
1311
03/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
33
03/solver01.py
Executable file
33
03/solver01.py
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
RE_LINE = re.compile('^#(\d+) @ (\d+),(\d+): (\d+)x(\d+)$')
|
||||
plan = dict()
|
||||
|
||||
|
||||
def read_input():
|
||||
with open('input.txt', 'r') as f:
|
||||
for line in f:
|
||||
yield line.strip()
|
||||
|
||||
def hash_position(x, y):
|
||||
return "{}x{}".format(x,y)
|
||||
|
||||
|
||||
for claim in read_input():
|
||||
m = RE_LINE.match(claim)
|
||||
if not m:
|
||||
raise Exception("unparsable input: {}".format(claim))
|
||||
|
||||
for x in range(int(m.group(4))):
|
||||
for y in range(int(m.group(5))):
|
||||
hash = hash_position(x+int(m.group(2)), y+int(m.group(3)))
|
||||
if hash not in plan:
|
||||
plan[hash] = []
|
||||
plan[hash].append(int(m.group(1)))
|
||||
|
||||
overlap = [ k for k,v in plan.items() if len(v) > 1]
|
||||
|
||||
print(len(overlap))
|
||||
|
||||
39
03/solver02.py
Executable file
39
03/solver02.py
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
RE_LINE = re.compile('^#(\d+) @ (\d+),(\d+): (\d+)x(\d+)$')
|
||||
plan = dict()
|
||||
all = dict()
|
||||
overlap = dict()
|
||||
|
||||
def read_input():
|
||||
with open('input.txt', 'r') as f:
|
||||
for line in f:
|
||||
yield line.strip()
|
||||
|
||||
def hash_position(x, y):
|
||||
return "{}x{}".format(x,y)
|
||||
|
||||
|
||||
for claim in read_input():
|
||||
m = RE_LINE.match(claim)
|
||||
if not m:
|
||||
raise Exception("unparsable input: {}".format(claim))
|
||||
|
||||
for x in range(int(m.group(4))):
|
||||
for y in range(int(m.group(5))):
|
||||
hash = hash_position(x+int(m.group(2)), y+int(m.group(3)))
|
||||
claim_id = int(m.group(1))
|
||||
all[claim_id] = True
|
||||
if hash not in plan:
|
||||
plan[hash] = []
|
||||
plan[hash].append(claim_id)
|
||||
if len(plan[hash]) > 1:
|
||||
overlap[plan[hash][-1]] = True
|
||||
overlap[plan[hash][-2]] = True
|
||||
|
||||
all = set(all.keys())
|
||||
overlap = set(overlap.keys())
|
||||
|
||||
print(all - overlap)
|
||||
Reference in New Issue
Block a user