diff --git a/d04.cc b/d04.cc index 1fb3fa8..059aa9c 100644 --- a/d04.cc +++ b/d04.cc @@ -15,9 +15,7 @@ public: bool overlaps(const Range &in) { return (min <= in.min && in.min <= max) - || (min <= in.max && in.max <= max) - || (in.min <= min && min <= in.max) - || (in.min <= max && max <= in.max); + || (in.min <= min && min <= in.max); } }; diff --git a/d04.py b/d04.py index 94c0363..c964fab 100644 --- a/d04.py +++ b/d04.py @@ -1,12 +1,8 @@ #!/usr/bin/env python3 from sys import stdin -data = [(range(int(a1), int(a2)+1), range(int(b1), int(b2)+1)) - for (a1, a2), (b1, b2) in [(a.split("-"), b.split("-")) +data = [(range(a1, a2+1), range(b1, b2+1)) for (a1, a2), (b1, b2) in + [(map(int, a.split("-")), map(int, b.split("-"))) for a, b in [x.split(",") for x in stdin.readlines()]]] print(sum(all(x in b for x in a) or all(x in a for x in b) for a, b in data)) print(sum(bool(set(a) & set(b)) for a, b in data)) - -for a, b in data: - if set(a) & set(b): - print((a,b))