diff --git a/day04.py b/day04.py index 937dab5..60fe29e 100644 --- a/day04.py +++ b/day04.py @@ -22,20 +22,10 @@ class Day(AOCDay): yield list(sorted(map(int, s1.split("-")))), list(sorted(map(int, s2.split("-")))) def part1(self) -> Any: - count = 0 - for s1, s2 in self.get_sections(): - if (s1[0] <= s2[0] and s1[1] >= s2[1]) or (s2[0] <= s1[0] and s2[1] >= s1[1]): - count += 1 - - return count + return sum((s1[0] <= s2[0] and s1[1] >= s2[1]) or (s2[0] <= s1[0] and s2[1] >= s1[1]) for s1, s2 in self.get_sections()) def part2(self) -> Any: - count = 0 - for s1, s2 in self.get_sections(): - if s1[0] <= s2[0] <= s1[1] or s2[0] <= s1[0] <= s2[1]: - count += 1 - - return count + return sum(s1[0] <= s2[0] <= s1[1] or s2[0] <= s1[0] <= s2[1] for s1, s2 in self.get_sections()) if __name__ == '__main__':