rj1
about | log | files | refs
commit 518c04983425fe26d92f89b6854c0e7266daf0f4
parent 20d942492186a6764fcd4069a36b1efda4ebde6a
author: rj1 <[email protected]>
date:   Sat,  3 Dec 2022 11:06:12 -0600

day 4 solution

Diffstat:
A2022/04/solution.py | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/2022/04/solution.py b/2022/04/solution.py @@ -0,0 +1,22 @@ +import os + +base_dir = os.path.realpath(os.path.dirname(__file__)) +with open(base_dir + "/input.txt", "r") as file: + input = file.read().rstrip() + +lines = input.split("\n") + +pairs = [] +for line in lines: + a, b = line.split(",") + pairs.append((a, b)) + +count = 0 +for a, b in pairs: + a1, a2 = map(int, a.split("-")) + b1, b2 = map(int, b.split("-")) + + if (a1 <= b2 and a2 >= b1) or (b1 <= a2 and b2 >= a1): + count += 1 + +print(count)