def count_overlapping_squares(claims): claimed_fabric = {} duplicated_squares = set() for claim_description in claims: claim = Claim(claim_description) for x in claim.get_x_range(): for y in claim.get_y_range(): coordinate = Coordinate(x, y).get_value() if coordinate in claimed_fabric: claimed_fabric[coordinate] = 'X' duplicated_squares.add(coordinate) else: claimed_fabric[coordinate] = claim.id return len(duplicated_squares)
def find_fully_isolated_claim(claims): claimed_fabric = {} intersected_claims = set() all_claims = set() for claim_description in claims: claim = Claim(claim_description) for x in claim.get_x_range(): for y in claim.get_y_range(): coordinate = Coordinate(x, y).get_value() if coordinate in claimed_fabric: claimed_fabric[coordinate].append(claim.id) for claim_id in claimed_fabric[coordinate]: intersected_claims.add(claim_id) else: claimed_fabric[coordinate] = [claim.id] all_claims.add(claim.id) return (all_claims - intersected_claims).pop()