예제 #1
0
 def setUp(self):
     self.claims = {
         1: Claim(1, 1, 3, 1 + 4, 3 + 4),
         2: Claim(2, 3, 1, 3 + 4, 1 + 4),
         3: Claim(3, 5, 5, 5 + 2, 5 + 2)
     }
     self.expected_unique_claim = 3
예제 #2
0
    def test_regex(self):
        rect_attrs = ('x1', 'y1', 'x2', 'y2')

        for string, claim2 in self.sample_input:
            claim1 = Claim.from_string(string)

            self.assertEqual(claim1.claim_id, claim2.claim_id)

            for attr in rect_attrs:
                self.assertEqual(getattr(claim2.rect, attr, None),
                                 getattr(claim1.rect, attr, None))
예제 #3
0
def get_input(path=INPUT_PATH):
    """Get the problem input from the data file.

    Reads the file line by line and builds a dict by calling the factory method on
    Claim. Invalid claims are filtered out. The keys are the claim IDs.

    Params:

    path - Path to input file"""
    with open(path) as f:
        claims = [Claim.from_string(line) for line in f]

    return {claim.claim_id: claim for claim in claims if claim is not None}
예제 #4
0
 def setUp(self):
     # All of this comes from the given sample input unless noted
     self.sample_input = (('#1 @ 1,3: 4x4', Claim(1, 1, 3, 1 + 4, 3 + 4)),
                          ('#2 @ 3,1: 4x4', Claim(2, 3, 1, 3 + 4, 1 + 4)),
                          ('#3 @ 5,5: 2x2', Claim(3, 5, 5, 5 + 2, 5 + 2)))
     self.claims = [c[1] for c in self.sample_input]
     self.sweep_events = {
         1: [(2, 3, 1)],
         3: [(1, 2, 1)],
         5: [(2, 3, -1), (3, 3, 1)],
         7: [(1, 2, -1), (3, 3, -1)]
     }
     # The last segment was always blank. Changing this from (1, 2, 2, 2, 1) and removing
     # the code that added the last interval, all unit tests still pass
     self.segtree_intervals = (1, 2, 2, 2)
     self.rectangle_y_intervals = (((3, 7), (2, 3)), ((1, 5), (1, 2)),
                                   ((5, 7), (3, 3)))
     # Transition sets with expected scores for both thresholds
     transition_set = (((2, 3, 1), ), ((1, 2, 1), ),
                       ((2, 3, -1), (3, 3, 1)), ((1, 2, -1), (3, 3, -1)))
     self.trans_threshold_1 = zip(transition_set, (4, 6, 6, 0))
     self.trans_threshold_2 = zip(transition_set, (0, 2, 0, 0))
예제 #5
0
def get_input(path=INPUT_PATH):
    """Get the problem input from the data file.

    Reads the file line by line and builds a list by calling the factory method on
    Claim. Invalid claims are filtered out.

    Params:

    path - Path to input file"""
    with open(path) as f:
        lines = [Claim.from_string(line) for line in f]

    # Invalid lines (blanks) will be None so filter them out
    return [claim for claim in lines if claim is not None]
예제 #6
0
from day3.claim import Claim

claims = {}
seen_points = set()
duplicate_points = set()

for line in open('input.txt'):
    claim = Claim(design=line)
    for point in claim.generate_points():
        if point in seen_points:
            duplicate_points.add(point)
        else:
            seen_points.add(point)

print("{} Square inches of fabric required by 2 or more claims".format(
    len(duplicate_points)))