puzzle3.py (981B)
1 file = [s[0:-1] for s in open('files/puzzle3.txt').readlines()] 2 fabric = [[0 for idx in range(1000)] for jdx in range(1000)] 3 4 for line in file: 5 tokens = line.split(',') 6 start_x = int(tokens[0].split('@')[1]) 7 temp = tokens[1].split(':') 8 start_y = int(temp[0]) 9 temp2 = temp[1].split('x') 10 for x in range(start_x, start_x + int(temp2[0])): 11 for y in range(start_y, start_y + int(temp2[1])): 12 fabric[x][y] += 1 13 14 print sum([sum([1 if y > 1 else 0 for y in x]) for x in fabric]) 15 16 for line in file: 17 tokens = line.split(',') 18 start_x = int(tokens[0].split('@')[1]) 19 temp = tokens[1].split(':') 20 start_y = int(temp[0]) 21 temp2 = temp[1].split('x') 22 claim_found = True 23 for x in range(start_x, start_x + int(temp2[0])): 24 for y in range(start_y, start_y + int(temp2[1])): 25 if fabric[x][y] > 1: 26 claim_found = False 27 28 if claim_found: 29 print line 30 break