-
-
Save gnyman/96d863559da87d3558b9cfbcaf9150b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Open the input file and read the lines | |
with open("input.txt") as file: | |
lines = file.read().strip().split("\n") | |
# Initialize the counter for fully contained ranges | |
counter = 0 | |
# Loop over the lines in the input file | |
for line in lines: | |
# Split the line into two parts by the comma | |
parts = line.split(",") | |
# Parse the first and second ranges | |
a = [int(x) for x in parts[0].split("-")] | |
b = [int(x) for x in parts[1].split("-")] | |
# Check if one range fully contains the other | |
if a[0] <= b[0] and b[1] <= a[1]: | |
counter += 1 | |
elif b[0] <= a[0] and a[1] <= b[1]: | |
counter += 1 | |
# Print the result | |
print(counter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment