diff options
author | Jack Sangdahl <[email protected]> | 2024-06-15 22:20:32 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2024-06-15 22:20:32 -0600 |
commit | 8e313e2614c7a0fe5af924febdbacc650e33835e (patch) | |
tree | 63426b6942ceebe17708140c972a7d7451bd2f74 /4_2022.py | |
download | aoc-8e313e2614c7a0fe5af924febdbacc650e33835e.tar.gz aoc-8e313e2614c7a0fe5af924febdbacc650e33835e.zip |
intial
Diffstat (limited to '4_2022.py')
-rw-r--r-- | 4_2022.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/4_2022.py b/4_2022.py new file mode 100644 index 0000000..0c5c781 --- /dev/null +++ b/4_2022.py @@ -0,0 +1,19 @@ +import sys + +infile = sys.argv[1] if len(sys.argv) > 1 else "4_2022.txt" +data = open(infile).read().strip() +lines = [x.strip() for x in data.split("\n")] +p1 = 0 +p2 = 0 +for line in lines: + one, two = line.split(",") + s1, e1 = one.split("-") + s2, e2 = two.split("-") + s1, e1, s2, e2 = [int(x) for x in [s1, e1, s2, e2]] + if s1 <= s2 and e2 <= e1 or s2 <= s1 and e1 <= e2: + p1 += 1 + if not (e1 < s2 or s1 > e2): + p2 += 1 + +print(p1) +print(p2) |