Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0536f6

Browse files
author
calypso
authored
Merge pull request #26 from sqdorte/master
03/2 - python
2 parents a744b53 + afd2586 commit d0536f6

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

2018/03_2/python/sqdorte.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
with open('input', 'r') as raw:
2+
i = raw.read().strip().split('\n')
3+
4+
claimed = {}
5+
claims = []
6+
7+
for x in i:
8+
claim = x.split('@ ')
9+
10+
cid = claim[0][1:]
11+
coords = claim[1].split(': ')
12+
13+
a,b = map(int, coords[0].split(','))
14+
c,d = map(int, coords[1].split('x'))
15+
16+
for x in range(a, a+c):
17+
for y in range(b, b+d):
18+
try:
19+
claimed[(x,y)] += 1
20+
except KeyError:
21+
claimed[(x,y)] = 1
22+
23+
claims.append((cid,a,b,c,d))
24+
25+
for cid,a,b,c,d in claims:
26+
s = True
27+
for x in range(a, a+c):
28+
if not s:
29+
break
30+
for y in range(b, b+d):
31+
if claimed[(x,y)] > 1:
32+
s = False
33+
break
34+
if s:
35+
print(cid)
36+
break

0 commit comments

Comments
 (0)